JPA: @ManyToOne legacy mapping using @JoinTable

Dear JEE experts,
I have a tough legacy mapping problem. There are two entities Pac and BasePac where each Pac has a BasePac field which is to be queried from the other entity table. The association is definied in a third table pac_component which has a Pac and a BasePac field among several others. I think the schema is a bit weird and I would have defined it differently, but I cannot change it because other applications using the database must not be changed.
My code looks like this:
@javax.persistence.Entity(name="Pacs")
@javax.persistence.Table(name="packet")
@javax.persistence.SequenceGenerator(name="PacsSeqGen", sequenceName="packet_packet_id_seq")
public class Pac
     implements java.io.Serializable
    // virtual attribute basePac
    @javax.persistence.ManyToOne(fetch=EAGER, optional=true) // optional should be default anyway
    @javax.persistence.JoinTable(
         name="packet_component",
         [email protected](name="packet_id"),
         [email protected](name="basepacket_id") )
    private BasePac basePac;
    public BasePac getBasePac() { return basePac; }
    public void setBasePac( BasePac basePac ) { this.basePac = basePac; }
@javax.persistence.Entity(name="BasePacs")
@javax.persistence.Table(name="basepacket")
@javax.persistence.SequenceGenerator(name="BasePacsSeqGen", sequenceName="basepacket_basepacket_id_seq")
public class BasePac
     implements java.io.Serializable
{ ... }The Entity for pac_component does not appear so far and afaik it does not matter.
When I now create a Pac instance and persist it, JPA (with Hibernate) always wants to create a link object:
insert into pac_component (basepacket_id, packet_id) values (?, ?)Where the ? for basepacket_id is null. But this is not a valid row for pac_component, thus I will get a ConstaintViolationException.
My question is: Why does it create this row at all? The association is marked optional!
My solution might be to make the field PacBase within Pac transient and access it only through a pacComponents field, which is a @OneToMany but every assiciated PacComponent entity refers to the same BasePac. Anyway, I wonder why JPA or Hibernate wants to create such a row at all.
... MIchael

I wouldn't focus too much on wanting to solve this through JPA. What you have here is a 'problem' which you will run into in many forms - your business requirements do not map directly to the data layer. This simply means that you need some business logic to make the translation. For example if this were for a web layer I would implement a specialized bean which can take different entities and then provide an alternative view on the data, optionally by generating it.
If 'calculated' data is closely tied to the database layer and less to the business layer then you could of course choose to fix it through the database itself - by creating a view and mapping an entity to that. That is especially useful if you need the same data in multiple aspects of the application framework and not only in the Java code (think of reporting and analysis for example), but it has other considerations like performance.

Similar Messages

  • JPA Object-Relational Mapping: how to deal with self-related mapping?

    ignore the post.
    sorry for my stupidity
    ==
    Hello,
    Suppose I have a class nemed Group, which can have sub-groups. It is defined like:
    @Entity
    Class Group{
    private int id;
    private String name;
    private Group parent; //M-1 mapping
    The problem is Group is mapped to itself:
    child group -- parent group
    M : 1
    How JPA supports that kind of relationship? Can I put both
    @Many-to-One and @One-to-Many over parent field like:
    @Many-to-One
    @One-to-Many
    private Group parent;
    Thanks a lot!
    Message was edited by:
    javasprinter

    One possibility could be the following - (included annotation mappings):
    @Entity
    Class Group{
    private int id; // probably should change to Integer to account for null data
    private String name;
    @ManyToOne
    @JoinColumn(name = "PARENT_GROUP_FK")
    private Group parent; //M-1 mapping
    @OneToMany
    @JoinTable ( name = "SUB_GROUPS",
    joinColumns = { @JoinColumn(name = "PARENT_GROUP_ID")},
    inverseJoinColumns = {@JoinColumn(name = "CHILD_GROUP_ID")}
    private List subGroups;
    Tables -
    Group - columns - id, name, parent_group_fk
    Sub_groups - columns - parent_group_id, child_group_id
    The above maps a unidirectional relationship from parent group to child groups, but that really isn't a big deal because you can always get the parent from the parent group id.
    I'm sure this isn't the best way, but it worked for me. HTH.

  • legacy-map false /legacy-map

    In the BlazeDS dev guide there is the following statement (when talking about explicitly mapping between Java and ActionScript) :
    http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=serialize_data_2.ht ml
    Note: In Flex 1.5, java.util.Map was sent as an associative or ECMA Array. This is no longer a recommended practice. You can enable legacy Map support to associative Arrays, but Adobe recommends against doing this.
    Why is this not recommended by Adobe?
    Kind regards,
    Fretzer.

    Thanks for your help Raff.  We got it working after making a firewall change and correcting an issue with the hook URL, which should have gone to a subdirectory.
    For anyone else using Spring 3, the aspect oriented setup works fine.
    @RemotingDestination(channels={"amf"})
    @Service("RTC")
    public class RTCHOOKS {
    Just make sure the class is contained in a package specified in
    <context:component-scan base-package="..." />

  • JPA: how to map a link table

    I have two tables:
    t1(t1_Id, col1, col2, col3)
    t2(t2_Id, col2, col2)
    and a link table
    link_table(t1_Id, t2_Id)
    Relationship between link_table and t1, link_table and t2 is many to one. Enties in link table are updatable.
    Any idea or suggestion about mapping (anotation) in JPA?

    Hello,
    EclipseLink has support for database object-relational datatypes, but they are not supported or exposed through JPA. Instead, you will need to leave it unmapped and then change the mapping, using a customizer to create the mapping described:
    http://wiki.eclipse.org/Introduction_to_Object-Relational_Data_Type_Mappings_(ELUG)#Object-Relational_Data_Type_Array_Mapping
    Best Regards,
    Chris

  • How to reconcile procedure or function in a mapping using OMB Plus?

    HI,
    Could any one please explain, how to reconcile a procedure or function used in a mapping?
    Thank you,
    Regards,
    Gowtham Sen.

    Hi,
    You can only reconcile Inbound (from Procedure to the mapping) :
    OMBRECONCILE PROCEDURE \
    '/[Project_name]/[Module_name]/[Procedure_name]
    TO MAPPING '[Mapping_name]' \
    OPERATOR '[for example name of a Post-Mapping Process in the mapping]' \
    USE (RECONCILE_STRATEGY 'REPLACE', MATCHING_STRATEGY 'MATCH_BY_OBJECT_ID')
    Hope that will help.
    Best Regards
    Samy

  • Reg - XSLT Mapping using stylesheet exception during test

    Hi experts,
    I am new to SAP PI. Currently i am working on PI's XSLT Mapping using Stylusstudio.
    I got error *Transformer Configuration Exception occurred when loading XSLT <name>.xsl; details: Could not compile stylesheet*.
    I tried test by selecting SAP XML TOOLKIT too, then i am facing
    *com.sap.engine.lib.xml.parser.NestedSAXParseException: Fatal Error: com.sap.engine.lib.xml.parser.ParserException: XMLParser: Prefix 'a' is not mapped to a namespace (:main:, row:4, col:15)(:main:, row=4, col=15) -> com.sap.engine.lib.xml.parser.ParserException: XMLParser: Prefix 'a' is not mapped to a namespace (:main:, row:4, col:15)*.
    Kindly help me to overcome this issue.

    Hi,
    Simply your XSLT file is not a well-formed XML. Check your syntax. You could also use the XML Tools plugin to Notepad++ to help you determine where the syntax error is precisely.
    Moreover, this error "Prefix 'a' is not mapped to a namespace" might mean that you are using a tag: <a:something>, but "a" is not properly declared as a namespace, for instance like: xmlns:a="something.sap.com".
    Hope this helps,
    Greg

  • N:1 mapping using XSLT

    Hi,
    I have a scenario in which i have to do a N:1 mapping using XSLT.
    I am doing this using the BpmPatternCollectMultiIf giving the XSLT mapping in the transformation step...
    But, the transformation step is returning the following error:
    Error: Exception CX_MERGE_SPLIT occurred (program: CL_MERGE_SPLIT_SERVICE========CP, include: CL_
    My XSLT mapping is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
         <item xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
              <KEYCODE>
                   <xsl:value-of select="ns0:Messages/ns0:Message1/fsxml/item/keycode"/>
                   </KEYCODE>
                   <DESCRIPTION>
                        <xsl:value-of select="ns0:Messages/ns0:Message1/fsxml/item/description"/>
                   </DESCRIPTION>
                   <CLASS>
                        <xsl:value-of select="ns0:Messages/ns0:Message1/fsxml/item/class"/>
                   </CLASS>
                   <ONE>
                       <xsl:value-of select="ns0:Messages/ns0:Message2/test/row/one"/>
                   </ONE>
                   <TWO>
                       <xsl:value-of select="ns0:Messages/ns0:Message2/test/row/two"/>                                                      </TWO>
              </item>
         </xsl:template>
    </xsl:stylesheet>
    Here,<b> fsxml</b> is the first message and<b> test</b> is the second message.
    Kindly let me know if there is any problem in the XSLT mapping.
    Thanks in advance,
    Thanks,
    Karen Pereira

    Hi,
    There was problem in the XSLT mapping. i figured it out and fixed it and the scenario worked.
    The new mapping was as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
         <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
         <xsl:template match="/">
              <ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
                   <ns0:Message1>
                        <item xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
                             <!-- Mapping for tags which are to be directly replicated in the target message-->
                             <KEYCODE>
                                  <xsl:value-of select="ns0:Messages/ns0:Message1/fsxml/item/keycode"/>
                             </KEYCODE>
                             <DESCRIPTION>
                                  <xsl:value-of select="ns0:Messages/ns0:Message1/fsxml/item/description"/>
                             </DESCRIPTION>
                             <CLASS>
                                  <xsl:value-of select="ns0:Messages/ns0:Message1/fsxml/item/class"/>
                             </CLASS>
                             <ONE>
                                  <xsl:value-of select="ns0:Messages/ns0:Message2/test/row/one"/>
                             </ONE>
                             <TWO>
                                  <xsl:value-of select="ns0:Messages/ns0:Message2/test/row/two"/>
                             </TWO>
                   </item>
                   </ns0:Message1>
              </ns0:Messages>
         </xsl:template>
    </xsl:stylesheet>
    Thanks,
    Karen

  • Error: 1:n multi-mapping using BPM for file to file scenario

    Hi. Iu2019m trying to do 1:n multi-mapping using bpm scenario. I use file to file. Input file consists of many records and then I want many record to be transformed into many file at target system. I follow step in http://www.riyaz.net/blog/xipi-1n-multi-mapping-using-bpm/. However, I have a problem when file is retrieved in to XI. It doesnu2019t create any output file.
    When I look at SXMB_MONI, it shows u201CNo object type found for the message Check that the corresponding process is activated.u201D Besides, it shows error message "Unable to perform action for selected message" when i clikc at PE in SXMB_MONI.
    I have check at many previous posts with the same error message but still couldnu2019t solve it. I already activate my BPM and check that status in SXI_CACHE = 0. There is noting left in change list of my IR and ID.
    Here is my design and configuration.
    IR
    Data Type: DT_file_split -> for both input and output file
    Message Type: MT_file_split_sender, MT_file_split_receiver
    Message Interface: SI_file_split_in, SI_file_split_out, SI_file_abs_source, SI_file_abs_target
    Message mapping: MM_file_split for mapping MT_file_split_sender with MT_file_split_receiver
    Interface mapping: OM_file_split
    u2022     Source = SI_file_split_out
    u2022     Target = SI_file_split_in
    u2022     Mapping Program = MM_file_split
    BPM following this link http://www.riyaz.net/blog/xipi-1n-multi-mapping-using-bpm/.
    ID
    Import my Integration process
    2 Communication Channel for getting input file (CC_File_split_sender) and creating output file (CC_File_split)
    2 Receiver determination:
    u2022     Source system to BPM using interface SI_File_Abs_source
    u2022     BPM to target system using interface SI_File_Abs_target
    1 Interface determination:
    u2022     from source system to BPM
    u2022     Sender interface: SI_File_Split_Out
    u2022     Receiver interface: SI_file_abs_source
    1 Sender Agreement
    u2022     Commu. Component: Source System
    u2022     Using interface: SI_File_Abs_source
    u2022     Sender Communication Channel: CC_File_Split_Sender
    1 Receiver Agreement
    u2022     Sender Communication Component: BPM
    u2022     Receiver Communication Component: Target System
    u2022     Receiver Interface: SI_File_Split_In
    u2022     Receiver Communication Channel: CC_File_Split
    Anyone know how to fix this?
    Thanks,
    Pavin

    Hi,
    Yes, thats the problem.
    You are creating file from test tab of  1..N mapping .
    In case of 1..N mappping in mapping Extra tags of messages are addded to the data.As shown here:-
    Messages
          Message1
               MessageType
    When you use this mapping to generate xml message then it will add additional tags for <Messages> and <Message1>, which is not correct. it should only have structure of you MT.
    So remove start and end tag of <Messages> and <Message1> from your data file. Mentioned below in bold.
    <xml......>
    <Messages>
    <Message1>
    <MT_...>
    </MT_...>
    </Message1>
    </Messages>
    This should solve your problem.
    Regards,
    Sami.

  • Create Attachment within Graphical Mapping using UDF

    Hi!
    We want to create an attachment witihn a graphical mapping using an UDF function.
    I use that function:
    public String addAttachment(String filename, String mimeType, String content, Container container) throws StreamTransformationException{
         BASE64Decoder decoder=new BASE64Decoder();
         try {
              GlobalContainer globalContainer = container.getGlobalContainer();
              OutputAttachments outputAttachments = globalContainer.getOutputAttachments();
              Attachment attachments = outputAttachments.create(filename, mimeType,decoder.decodeBuffer(content));
              outputAttachments.setAttachment(attachments);
              return "Adde1: "+filename;
         } catch (Exception e) {
              return e.toString();
    (SDN helped me much in creating that
    This function has no compiling errors, anything workes fine:
    It takes 3 input-parameters, see also: http://help.sap.com/javadocs/pi/SP3/xpi/com/sap/aii/mapping/api/OutputAttachments.html
    filename (ok, more or less contentID)
    mimeType (more or less contentType)
    content: Base64-encoded String which should be set as content
    In my sample I use the following constants for that function:
    filename = "fn1.txt"
    mimeType="application/xml"
    content = "UG9seWZvbiB6d2l0c2NoZXJuZCBhw59lbiBNw6R4Y2hlbnMgVsO2Z2VsIFLDvGJlbiwgSm9naHVydCB1bmQgUXVhcms=" --> cames directly from http://de.wikipedia.org/wiki/Base64
    When using the message, I got this error within SXMB_MONI:
    <SAP:AdditionalText>com.sap.engine.interfaces.messaging.api.exception.MessagingException: Could not queue receive for
    message 0022642d-b106-02df-8e8c-f41c243bd112(INBOUND). Reason: java.lang.NullPointerException: while trying to
    invoke the method com.sap.aii.af.sdk.xi.lang.Binary.getBytes() of an object returned from
    com.sap.aii.af.sdk.xi.mo.xmb.XMBPayload.getContent()</SAP:AdditionalText>
    This looks pretty much the same as Add Attachment from ABAP Mapping but this tread is also not answered.
    Adding attachment from PI level looks also in that direction, again, no answer.
    So, I was wondering if someone has solved such problem?

    Hi Divyesh!
    We did it that way:
    1. Choosing the XML-Mailstructure as Destination as described in Configuring the Receiver Mail Adapter - Advanced Adapter Engine - SAP Library -  Example (XI payload with mail package)
    2. now we have created a UDF for creating the "content"
    public void getContent(String[] text, String[] attFname, String[] attType, String[] attContent, ResultList result, Container container) throws StreamTransformationException{
    // vergleich ob alle att-Arrays selbe anzahl haben
    if (attFname.length!=attType.length || attFname.length!=attContent.length) {
        result.addValue(Integer.parseInt("Fehler: alle Attachment-Eingänge müssen die selbe Anzahl an Elementen haben!"));
        String CRLF = "\r\n";
        String output="This is a multi-part message in MIME format."+CRLF+CRLF+
        "--"+getBoundary(container)+CRLF+
        "Content-Type: text/plain; charset=UTF-8"+CRLF+
        "Content-Disposition: inline" + CRLF + CRLF +
        text[0]+CRLF;
    for (int i=0;i<attFname.length;i++) {
        output+="--"+getBoundary(container)+CRLF+
        "Content-Type: "+attType[i]+"; name="+((char)34)+attFname[i]+((char)34)+CRLF+
        "Content-Disposition: attachment; filename="+((char)34)+attFname[i]+((char)34)+CRLF+
        "Content-Transfer-Encoding: Base64"+CRLF+CRLF+attContent[i]+CRLF;
    output+="--"+getBoundary(container)+CRLF;
    result.addValue(output);
    This UDF is configured as "QUEUE"
    We have configured this input-structure
    The Content itself is allready base64.
    So we can call this mapping and it creates a Multipart-Mail for us.

  • Is it possible to do message mapping using different namespace message type

    Hi all,
    Is it possible to do message mapping using different namespaces message types
    Example :
    i am having message type MT_1 in namespace http://sap.com/abc
    and second message type MT_2 in namespace http://partner.com/xyz
    so MT_1 can be mapped with MT_2 or not having different namespace.
    Thanks

    Read through my reply in this thread for Defining Software component dependencies.
    Though it explains this for Improted Archives, it also holds true for Message Types to be used in message mappings.
    Re: Payload Extraction
    Regards
    Bhavesh

  • How to test ABAP mapping used in a Integration Process node

    Hi,
    anyone can suggest me how to debug an ABAP mapping used into a transformation node belonging to an Integration Process ?
    Thanks.
    Francesco

    Hi, Francesco.
    I've debugged ABAP Mapping with SXI_MAPPING_TEST transaction.
    If you have creted a scenario including your ABAP Mapping, you only hace to put the correct sender/sender interface and receiver/receiver interface. You have to put some XML document as an input.
    I wrote in my code the Break-point instruction an debugged the process without problems.
    regards,
    Francisco

  • JAVA mapping using SAX parser adds extra tags

    Hi,
      We are using  java mapping using a SAX parser.It works well in standalone application ie it parses correctly and gets our desired xml structure and the xml is well formed too but when we import it in XI as a jar file it does not throw any errors but adds extra start tags, as a result the output xml is not well formed.XI is adding extra start tags.
    If any one else has faced a similar situation please help.
    Regards,
    Anirban.

    Hi Roberto,
    Thank you for the response.
    As I said, it doesnt throw any error. It is working perfectly in standalone application. But when we deploy it to XI Server, it is not forming the well formed XML. We too are puzzled by this situation.
    Okay, i will explain my scenario here.
    The following is my input XML to the java pgm..
    <Header>
    </Header>
    <Body>
    </Body>
    <SubBody1>
    </SubBody1>
    <SubBody2>
    </SubBody2>
    <SubBody3>
    </SubBody3>
    <SubBody4>
    </SubBody4>
    <Trail>
    </Trail>
    The desired output is
    <Header>
      <Body>
         <NameChanged1>
            <NameChanged2>
    <SubBody3>
    <SubBody4>
    </SubBody4>
    </SubBody3>
    </NameChanged2>
    </NameChanged1>
    <Trail>
    </Trail>
    Just look at the SubBody2 and SubBody1 node, its tag name has been changed in the output XML. Thats y i have decided to use java mapping instead of message mapping.
    I have developed the code for everything, i.e for changing the tag name and for forming the nested xml and it is working fine as a standalone application. But while deploying it to XI, the output is not well formed. I dont know the reason for it. Even I have checked the cardinality of the output Data types, that I have created. Its perfectly okay with all.
    Any Ideas???
    Regards,
    Anirban

  • MAPPING USING FLAT FILE SOURCE MODULE

    I created a mapping using a flat file as source and a dimension as target, I've already configure both modules and their locations.
    When I try to deploy this mapping in the deploy manager, it generates the script for the control file and when I hit the deploy button it says that the deploy was succesfull, but I really don�t know what it did.
    Does it put the file in my target schema?, what do I suposs to do next?

    Hi,
    So,i don't have to manually run the sql loader from the command prompt???
    All i have to do is Execute the map normally from the deployment manager and it will load the .ctl file itself.Ok great,i did so but i got the following error:
    Starting Execution BM_DEBIT_CARDS_DAT_MAP
    Starting Task BM_DEBIT_CARDS_DAT_MAP
    C:\Documents and Settings\CORAL 2000\Desktop\Flat filesBM_DEBIT_CARDS_DAT_MAP.ctl (The file access permissions do not allow the specified action.)
    RPE-01008: Recovery of this request is in progress.
    RPE-01009: Completion of this task could not be completed due to an earlier system failure.
    Completing Task BM_DEBIT_CARDS_DAT_MAP
    Completing Execution BM_DEBIT_CARDS_DAT_MAP
    So are there any permissions i should grant or what?
    Dina Nagia

  • How to dynamically configure JPA setting at runtime using java code?

    Hi,
    I am new to EJB 3.0 and JPA. I am trying to help my company to deploy the use of JPA in EJB3.0. Currently, i am trying out with OpenJPA in IBM Webshpere Application Server 7.0. We have four different WAS servers running for testing, system integration testing, user testing and production respectively, and in each region, the configurations for data source, JDBC username and password, schema, etc are different. So i think i would need to configure the JPA setting during runtime using Java code that determines which is the environment. And apparently i am stuck with the limited knowledge i have.
    1) I understand that i could override the JDBC in the persistence xml by creating entity manager using entity manager factory. But is it possible that i do similar thing by using inejction of persistence context on entity manager to obtain a container managed entity manager?
    2) Alternatively, it is possible to create multiple persistence unit in the XML and inject different PU to the entity manager, am i right? But how to inject dynamically since @PersistenceContext(unitName="xxx") only accepts constant declaration.
    3) Is it possible that the JDBC username and password are read from properties file?
    Thanks for your help in advance!

    Hi
    Thanks for the reply.
    Are you saying that i have to configure the data source authentication to the backend DB2 using the JAAS-J2C? Correct me if i am mistaken. I guess i am unable to do so as the application server setup only contains one data source, and the server hosted a number of applications. Every applications has their own JDBC username and password supply to the data source (the ID supplied at the DB2 side will decide which resource can access) and thus, i have to supply the username and password at runtime. Talked to the server guy and seems that it is not feasible to have seperate datasource for each applications as considered to the volume of applications hosted inside the server.
    Any suggestion?

  • Mapping using Java Coding

    I've got a big trouble. First, I'm trying to do mapping using Java Coding based on the TopLink Developer's Guide.
    I'm using a Employee's Table as usual, but here is the problem, I can not do inserting on the database after I do mapping. As a note, there is no error compile and also I can do the session login already.
    Employee.java
    public class Employee extends oracle.toplink.sessions.Project{
         private Long id;
         private String fnama;
         private String lnama;
    public Employee() {
    setName("ObjectTab");
    applyLogin();
    addDescriptor(empDesc());
    conformAllDescriptors();
    public String getFnama() {
         return this.fnama;
    public String getLnama() {
         return this.lnama;
    public void setFnama(String fnama) {
         this.fnama = fnama;
    public void setLnama(String lnama) {
         this.lnama = lnama;
    public void applyLogin() {
    DatabaseLogin login = new DatabaseLogin();
    // use platform appropriate for underlying database
    login.usePlatform(
    new oracle.toplink.platform.database.oracle.Oracle9Platform());
    login.setDriverClassName("oracle.jdbc.OracleDriver");
    login.setConnectionString("jdbc:oracle:thin:localhost:1521:pusat");
    login.setUserName("tryo");
    login.setEncryptedPassword("a, ENCRYPTED");
    // Configuration Properties
    setDatasourceLogin(login);
    public ClassDescriptor empDesc() {
    ObjectRelationalDescriptor descriptor = new ObjectRelationalDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setTableName("EMPLOYEES");
    descriptor.setStructureName("EMPLOYEE_T");
    descriptor.setPrimaryKeyFieldName("ID");
    descriptor.addFieldOrdering("ID");
    descriptor.addFieldOrdering("F_NAME");
    descriptor.addFieldOrdering("L_NAME");
    descriptor.addDirectMapping("id", "OBJECT_ID");
    descriptor.addDirectMapping("fnama", "F_NAME");
    descriptor.addDirectMapping("lnama", "L_NAME");
    return descriptor;
    Main Class:
    protected String getSessionsXmlPath() {
    return "sessions.xml";
    protected String getSessionName() {
    return "Session";
    protected void createSession() {
    XMLSessionConfigLoader loader = new XMLSessionConfigLoader(getSessionsXmlPath());
    SessionManager mgr = SessionManager.getManager();
    session = (DatabaseSession)mgr.getSession(loader, getSessionName(), Thread.currentThread().getContextClassLoader(), true, true);
    public static void closeSession(){
    SessionManager.getManager().destroyAllSessions();
    session = null;
    private void jButton1_actionPerformed(ActionEvent e) {
    Employee myEmp = new Employee();
    createSession();
    private void jButton2_actionPerformed(ActionEvent e) {
    Employee theEmp = new Employee();
    UnitOfWork uow = session.acquireUnitOfWork();
    try{
    theEmp.setFnama("A");
    theEmp.setLnama("B");
    uow.commit();
    }finally{
    uow.release();
    For everybody who already knows the solution, please reply as soon as possible. Because I really need this solution to finish my last final project.
    Thanks

    When you create a new instance you must register it with the UnitOfWork in order to have the new entity persisted.
    Employee theEmp = new Employee();
    UnitOfWork uow = session.acquireUnitOfWork();
    theEmp.setFnama("A");
    theEmp.setLnama("B");
    uow.registerObject(theEmp);
    uow.commit();
    Doug

Maybe you are looking for