2 Replies Latest reply: Jan 6, 2013 2:37 AM by 973511 RSS

    How to save an entity with description and a file?

    973511
      Hi everybody!
      I have an entity Video:
      @Entity
      public class Video {
      @PrimaryKey
      private String title;
      @SecondaryKey(relate = MANY_TO_ONE, relatedEntity=Journalist.class)
      private String jorName;
      @SecondaryKey(relate = MANY_TO_ONE, relatedEntity=Operator.class)
      private String oName;
      @SecondaryKey(relate = MANY_TO_ONE)
      private Date date;
      @SecondaryKey(relate = MANY_TO_ONE)
      private String place;
      private File file;
      ....
      }
      the video accesor for PK is:
      PrimaryIndex<String,Video> pIdx=store.getPrimaryIndex(String.class, Video.class);

      A user opens a form(it is written in swing) and fills in the title, name of the author, date, place of the video and browsers a file from some source. Now the user presses button "upload" and the whole object must be put to database. I dont understand how the whole object(file with filled description) can be put to db?
      Below is actionPerformed function:

      public void actionPerformed(ActionEvent e) {
      Object source = e.getSource();
      if (e.getSource() == btnBrowse) {
      int returnVal = fc.showOpenDialog(VideoPanel.this);

      if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fc.getSelectedFile();
      textField.setText(file.toString());

      if(source == btnUpload){
      if(text1.getText().equals("")&&text2.getText().equals("")&&text3.getText().equals("")){
      //how to put the whole object?
      }

      Thanks in advance!
        • 1. Re: How to save an entity with description and a file?
          Greybird-Oracle
          Hello,
          I dont understand how the whole object(file with filled description) can be put to db?
          Have you read the documentation and examples about how to use the com.sleepycat.persist API to write and read persistent objects? If so, what specifically is confusing? Be sure to look at the example programs.

          We can help with questions about our APIs, once you've read the doc, but please understand that we won't be able to supply you with the code to integrate with your Swing app -- that's your job.

          --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
          • 2. Re: How to save an entity with description and a file?
            973511
            When I try to save entity the following error message appeares: java.lang.IllegalArgumentException: Class could not be loaded or is not persistent: java.io.File

            The entitty class contains a field - File file:
            @Entity
            public class Vid {
            @PrimaryKey
            private String name;
            private String phoneNumber;
            private String position;
            private File file;
            ...}
            By loading the class into DB this File causes problem:
            private void run()
            throws DatabaseException, FileNotFoundException, IOException {
            myDbEnv.setup(myDbEnvPath);
            da=new DA(myDbEnv.getEntityStore());
            Vid v=new Vid();
            v.setPKId("title");
            v.setNumber("123");
            v.setAddress("posit");
            v.setPosition("E:\\News\\P1020002.MOV");
            da.pIdx.put(v);

            }

            Could you give a hint how to resolve the problem?

            thanks in advance

            Nina