2 Replies Latest reply on Mar 5, 2009 1:33 AM by kragoth

    Persistence Q: How to use a sequence-generated value on another class?

    dolanp.dolanp.gmail.com

      Hello all, hopefully someone can help me with this problem I've got.


      I have an entity bean called FileNamingTemplate with the following ID field:


           @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="fntGen")
           @SequenceGenerator(name="fntGen", sequenceName="FILE_NAME_TMPLT_SEQ")
           @Id @NotNull
           @Column(name="FILE_NAME_TMPLT_ID")
           public Integer getFileNameTemplateId() {
                return fileNameTemplateId;
           }
      



      I have another entity bean called FileNamingAttribute which has its own sequence-generated ID.  It also maintains a link back to the FileNamingTemplate that it belongs to.


           @Column(name="FILE_NAME_TMPLT_ID")
           public Integer getFileNamingTemplateId() {
                return fileNamingTemplateId;
           }
      




      So the issue I have is that I am persisting a FileNamingTemplate and several FileNamingAttribute objects in the same transaction, and I need to get the sequence-generated value from the FileNamingTemplate's ID field into the FileNamingAttribute's fileNamingTemplateId field.  I know this is possible using ManyToOne relationships but for design reasons if it's possible I'd like to find another way to do it.  If I try to set the value like so after I've merged the template:


      fna.setFileNamingTemplateId(template.getFileNameTemplateId())


      It does not work, just gives it a null value.


      Any ideas or is this not even possible?  Thanks.