Variable one to many relation

Hello, I need help.
I have classes Dog and Cat both extends from abstract Animal. Also I have class Zoo that has a collection of classes Animal.
There is a table for Zoo and tables for Dog and Cat both have zoo_id.
How can I map animals collection to both tables????
Thanks!!!
Adrian

The simplest way to do this is to use TopLink's inheritance mapping. Map the Animal class to a table with all of the common attributes between Cat & Dog. This table must have a way to identify a row as belonging to a Cat or a Dog. This is mot often accomplished with a type column.
This will allow you to have 1:1, 1:M, & M:M heterogeneous relationships to the Animal class.
Doug

Similar Messages

  • How to get data from three tables (A,B,C) having one to many relation between A and B .and having one to many reation between b and c

    i have  three tables A,B,C.  there is one to many relation between A and B. and one to many relation existed between table b and c . how will get data from these three tables

    check if this helps:
    select * --you can always frame your column set
    from tableA a
    left join tableB b on a.aid=b.aid
    left join tableC c on c.bid=b.bid
    This is just a general query. However, we can help you a lot more, if you can post the DDL + sample data and required output.
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • How to create one to many relation database based on existing Tables?

    Let say I have got 10 tables. Out of these 10 tables one table is used to navigate to other tables and at the some time providing some useful information. Therefore other 9 Tables have the identical structure.
    The question is, how can I convert these 10 tables into 2 tables, ie each row of first table correspond to the different data of the other table (one to many relation)?

    Hello,
    >>The question is, how can I convert these 10 tables into 2 tables, ie each row of first table correspond to the different data of the other table (one to many relation)?
    I do not quite understand what you ask and I doubt if Entity Framework supports this scenario, since you mentions these tables already exist, after importing them to the designed windows, we cannot modify them or it would throw an error shows the database
    and model is mismatched.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • JPA: Issue with loading One To Many relation

    Hi All,
    I have a One to Many relation mapped as below
    @Entity
    @Table(name="ACCOUNT_TABLE")
    public class UserAccount {
         // Attributes
         @Id
         @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="USER_SEQ")
         @SequenceGenerator(name="USER_SEQ", sequenceName="USERS_SEQ",allocationSize=1)
         @Column(name="CLIENT_ID")
         private Long clientId;
         @Column(name="USER_ID")
         private String userId;
         @OneToMany(fetch=FetchType.LAZY, mappedBy="userAccount")
         @JoinColumn(name="USER_ID", referencedColumnName="USER_ID", insertable=false, updatable=false)
         private List<UserRole> assignedRoles;
    @Entity
    @Table(name = "ROLE_TABLE")
    public class UserRole extends BaseEntity implements Serializable {
         private static final long serialVersionUID = -1651953276532642312L;
         @Id
         @Column(name = "USER_ID", length = 30, nullable=false, insertable=false, updatable=false)
         private String userId;
         @Column(name = "BUSINESS_CODE", length = 10, nullable=false, insertable=false, updatable=false)
         private String businessCode;
         @Column(name = "ROLE_NAME", length = 30, nullable=false, insertable=false, updatable=false)
         private String roleName;
         @ManyToOne()
         @JoinColumn(name="USER_ID", referencedColumnName="USER_ID", insertable=false, updatable=false)
         private UserAccount userAccount;
    As you may have noticed, the tables are not joined on the Primary key of parent. This is legacy schema and I have to work with it.
    Account and Role are joined by the USER_ID column. This I specified by providing JoinColumn.
    Then I have a DAO to retrieve the relation based on user id.
    public class UserAccountDAOJPAImpl UserAccountDAO{
         private static final String USER_ACCOUNT_BY_USERID = "select distinct ua " +
         "from UserAccount ua " +
         "left outer join fetch ua.assignedRoles ar " +
         "where ua.userId = ?1 ";
         public UserAccount findByUserName(String userName){          
              UserAccount userAccount=null;
              List<UserAccount> userAccounts =null;
         Query query = this.entityManager.createQuery(USER_ACCOUNT_BY_USERID);
         query.setParameter(1, userName.toUpperCase());
         userAccounts = query.getResultList();
         if(!userAccounts.isEmpty()) {
              userAccount=userAccounts.get(0);
              return userAccount;
    When I test this code ( for the user Id I used in test there are 11 roles )
    The SQL generated is correct, when I run the SQL in PL/SQL Developer, it returns the results as expected.
    But the DAO method above returns one UserAccount object with List of 11 UserRole objects as expected. But all of these 11 UserRole objects are same, where as the query returns 11 different roles.
    I couldn't figure out what I was doing wrong.
    Any help is appreciated.
    thanks,
    Raghavan

    @OneToMany(fetch=FetchType.LAZY, mappedBy="userAccount")
    @JoinColumn(name="USER_ID", referencedColumnName="USER_ID", insertable=false, updatable=false)
    private List<UserRole> assignedRoles;
    }What do you get when you remove this @JoinColumn annotation? It shouldn't be necessary. (user_id seems a little suspect as the join column name by the way, I would have expected role_id here...)

  • Primary one-to-many relation

    What is the best practice to identify the primary entity in a one-to-many relation?
    Lets asume the following:
    I have persons. (Table: PERSON, Primary Key: PERSON_ID)
    I have contact points (Table: CONTACT_POINTS, Foreign Key to PERSON_ID)
    In the E-Business Suite we have a field PRIMARY_FLAG on the CONTACT_POINTS table. This is either Y or N. Now it is upon the application, to verify that only one primary contact point is set. But there is no check in the database. You can have 2 lines, with primary_flag = 'Y'.
    This would make it heavy to do a simple select as:
    SELECT p.first_name, p.last_name, cp.phone_number FROM PERSON p, CONTACT_POINTS cp WHERE cp.PERSON_ID(+) = p.PERSON_ID AND cp.PRIMARY_FLAG(+) = 'Y'
    Because if you have, by mistake, 2 lines with PRIMARY_FLAG = 'Y', you would get 2 result lines in the query above, which is not wanted.
    A second way would be to have the PRIMARY_FLAG field is filled either with Y or NULL. In addition I can set a unique constrain over PERSON_ID and PRIMARY_FLAG and the database will block every try to add a second Y for one person. In that way I can be sure that I either have a primary contact point or I do not have one. So the query will result the same number of lines as there are in the PERSON table. BUT: whenever I go that way, I have to verify my application logic, that every change on the primary flag must set the old primary entry off and then insert or update the new primary entry.
    Which one is the best way, in practice? Are there other solutions? What are advantages ?
    Best Regards
    Alexander

    You can create unique function based index on your CONTACT_POINTS table as follows:
    (person_id, case when primary_flag = 'Y' then primary_flag else null end)
    So as soon as you'll insert another row with Y, you'll get error, but with other values like N, all will be OK.
    And yes - I think it is worth to check data integrity in DB :)
    Gints Plivna
    http://www.gplivna.eu

  • TopLink11 Tutorial problems with one-to-many relation

    Hi,
    I installed TopLink 11 and the related tutorial to work in a simple Eclipse project.
    Everthing works fine except for the storing of the one-to-many relation in the database.
    The tutorial works with employee, address and phone tables/classes. Plain Objects can be stored and one-to-one relations too. However when trying to store a one-to-many relation not the key of the related object (which is at that tome well known) but the object is tried to be entered
    in the Logfile I find:
    [TopLink Fine]: 2008.01.10 10:27:28.748--DatabaseSessionImpl(12916846)--Connection(9550256)--Thread(Thread[main,5,main])--INSERT INTO EMPLOYEE (EMP_ID, L_NAME, F_NAME, ADDR_ID, VERSION) VALUES (?, ?, ?, ?, ?)
         bind => [1501, Pascal, Blaise, 2252, 1]
    [TopLink Finer]: 2008.01.10 10:27:28.748--DatabaseSessionImpl(12916846)--Connection(9550256)--Thread(Thread[main,5,main])--commit transaction
    [TopLink Finer]: 2008.01.10 10:27:28.748--UnitOfWork(14858725)--Thread(Thread[main,5,main])--end unit of work commit
    [TopLink Finer]: 2008.01.10 10:27:28.748--UnitOfWork(14858725)--Thread(Thread[main,5,main])--release unit of work
    [TopLink Finer]: 2008.01.10 10:27:28.748--UnitOfWork(14858725)--Thread(Thread[main,5,main])--release unit of work
    [TopLink Finest]: 2008.01.10 10:27:28.748--UnitOfWork(18511661)--Thread(Thread[main,5,main])--Register the object Employee: Blaise Pascal
    [TopLink Finest]: 2008.01.10 10:27:28.748--UnitOfWork(18511661)--Thread(Thread[main,5,main])--Execute query DoesExistQuery()
    [TopLink Finer]: 2008.01.10 10:28:58.370--UnitOfWork(18511661)--Thread(Thread[main,5,main])--begin unit of work commit
    [TopLink Finer]: 2008.01.10 10:28:58.370--DatabaseSessionImpl(12916846)--Connection(9550256)--Thread(Thread[main,5,main])--begin transaction
    [TopLink Finest]: 2008.01.10 10:28:58.370--UnitOfWork(18511661)--Thread(Thread[main,5,main])--Execute query UpdateObjectQuery(Employee: Blaise Pascal)
    [TopLink Finest]: 2008.01.10 10:28:58.386--UnitOfWork(18511661)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(PhoneNumber[desk]: (603) 123-4567)
    [TopLink Fine]: 2008.01.10 10:28:58.386--DatabaseSessionImpl(12916846)--Connection(9550256)--Thread(Thread[main,5,main])--INSERT INTO PHONE (P_NUMBER, EMP_ID, AREA_CODE, TYPE) VALUES (?, ?, ?, ?)
         bind => [1234567, {Employee: Blaise Pascal}, 603, desk]
    [TopLink Warning]: 2008.01.10 10:28:58.511--UnitOfWork(18511661)--Thread(Thread[main,5,main])--Local Exception Stack:
    Exception [TOPLINK-4002] (Oracle TopLink - 11g Technology Preview 3 (11.1.1.0.0) (Build 071214)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Ungültiger Spaltentyp Error Code: 17004
    the highlighted section should be 1501 (the key of the employee record)
    Any ideas how to fix this?
    Thanks Erika

    Erika,
    You need to specify the other side of the relationship (on the PhoneNumber side), which is done by putting a @ManyToOne annotation on the "employee" attribute in PhoneNumber. That will cause TopLink to know that it is a relationship and not a basic mapping.
    -Mike

  • One to many relation doesn't work

    I tried without success to get a simple one to many relationship to work.
    The select works fine but
    I still have problems with insert.
    I have two tables on a existing schema:
    1     ANAG (ID_ANAG primary key,...)
    2     INDI (ID_INDI primary key, ID_ENTITA,...), where INDI.ID_ENTITA points
    to ANAG.ID_ANAG
    the two classes are:
    1     public class Anagrafica
         private int idAnag; //ID_ANAG
         private String ragSoc;
         private String ragSocFonet;
         private String codFisc;
         private String sesso;
         private Integer codTit;
         private Date dtNasc;
         private HashSet indis;
    2     public class Indirizzo
         private int idIndi; //ID_INDI
         private long idEntita; //ID_ENTITA
         private long tpEntita;
         private String indirizzo;
         private String localita;
         private String prov;
         private String cap;
         private Anagrafica anagrafica;
    the two metadata:
    1      anagrafica.jdo:
    <?xml version="1.0"?>
    <!-- This JDO Metadata file was auto-generated on 08/10/02 17.44.
    See http://www.solarmetric.com for Kodo JDO Documentation and examples. -->
    <jdo>
    <package name="domain">
    <class name="Anagrafica"
    identity-type="application"
    objectid-class="domain.AnagraficaPK">
    <extension key="table" value="ANAG" vendor-name="kodo"/>
    <extension key="class-column" value="none" vendor-name="kodo"/>
    <extension key="lock-column" value="none" vendor-name="kodo"/>
    <field name="idAnag" primary-key="true">
    <extension key="data-column" value="ID_ANAG"
    vendor-name="kodo"/>
    </field>
    <field name="ragSoc">
    <extension key="data-column" value="RAG_SOC"
    vendor-name="kodo"/>
    </field>
    <field name="ragSocFonet">
    <extension key="data-column" value="RAG_SOC_FONET"
    vendor-name="kodo"/>
    </field>
    <field name="codFisc">
    <extension key="data-column" value="COD_FISC"
    vendor-name="kodo"/>
    </field>
    <field name="sesso">
    <extension key="data-column" value="SESSO"
    vendor-name="kodo"/>
    </field>
    <field name="codTit">
    <extension key="data-column" value="COD_TIT"
    vendor-name="kodo"/>
    </field>
    <field name="dtNasc">
    <extension key="data-column" value="DT_NASC"
    vendor-name="kodo"/>
    </field>
    <field name="indis">
    <collection element-type="domain.Indirizzo"/>
    <extension vendor-name="kodo" key="table" value="INDI"/>
    <extension vendor-name="kodo" key="inverse"
    value="anagrafica"/>
    <extension vendor-name="kodo" key="idEntita-ref-column"
    value="ID_ANAG"/>
         </field>
    </class>
    </package>
    </jdo>
    2 Indirizzo.jdo
    <?xml version="1.0"?>
    <!-- This JDO Metadata file was auto-generated on 08/10/02 17.21.
    See http://www.solarmetric.com for Kodo JDO Documentation and examples. -->
    <jdo>
    <package name="domain">
    <class name="Indirizzo"
    identity-type="application" objectid-class="domain.IndiPK">
    <extension key="table" value="INDI" vendor-name="kodo"/>
    <extension key="class-column" value="none" vendor-name="kodo"/>
    <extension key="lock-column" value="none" vendor-name="kodo"/>
    <!--extension vendor-name="kodo" key="idEntita-data-column"
    value="ID_ENTITA"/-->
    <field name="idIndi" primary-key="true">
    <extension key="data-column" value="ID_INDI"
    vendor-name="kodo"/>
    </field>
    <field name="idEntita">
    <extension key="data-column" value="ID_ENTITA"
    vendor-name="kodo"/>
    </field>
    <field name="tpEntita">
    <extension key="data-column" value="TP_ENTITA"
    vendor-name="kodo"/>
    </field>
    <field name="indirizzo">
    <extension key="data-column" value="INDIRIZZO"
    vendor-name="kodo"/>
    </field>
    <field name="localita">
    <extension key="data-column" value="LOCALITA"
    vendor-name="kodo"/>
    </field>
    <field name="prov">
    <extension key="data-column" value="PROV"
    vendor-name="kodo"/>
    </field>
    <field name="cap">
    <extension key="data-column" value="CAP"
    vendor-name="kodo"/>
    </field>
    <field name="anagrafica">
    <extension vendor-name="kodo" key="idAnag-data-column"
    value="ID_ENTITA"/>
    </field>
    </class>
    </package>
    </jdo>
    The problem is:
    I create a new Anagrafica object and then I try to save it in the
    database. These are the SQL
    statements that are generated:
    INSERT INTO ANAG(DT_NASC, COD_FISC, RAG_SOC_FONET, SESSO, ID_ANAG,
    RAG_SOC, COD_TIT)
    VALUES (NULL, NULL, 'NATALE', NULL, 971963921, 'Natale', NULL)
    INSERT INTO INDI(TP_ENTITA, PROV, LOCALITA, ID_ENTITA, ID_INDI, INDIRIZZO,
    CAP)
    VALUES (0, NULL, NULL, 0, 971963921, 'via 25 dicembre', NULL)
    Why is the value of ID_ANAG (971963921) assigned to ID_INDI and not to
    ID_ENTITA?
    Regards
    Mirko

    Abe White wrote:
    <field name="indis">
    <collection element-type="domain.Indirizzo"/>
    <extension vendor-name="kodo" key="table" value="INDI"/>
    <extension vendor-name="kodo" key="inverse"
    value="anagrafica"/>
    <extension vendor-name="kodo" key="idEntita-ref-column"
    value="ID_ANAG"/>
         </field>
    Get rid of all extensions except the inverse:
    <field name="indis">
    <collection element-type="domain.Indirizzo"/>
    <extension vendor-name="kodo" key="inverse" value="anagrafica"/>
    </field>
    As in the examples in our documentation, all 1-many relations should only
    list their inverse 1-1 relation.
    Also, make sure your object model is consistent; i.e. make sure you'resetting
    both sides of the relation:
    indi.setAnagrafica (anag);
    anag.getIndis ().add (indi);
    Let us know if you continue to have problems.Hi Abe,
    I got rid of the unnecessary extensions and I set both sides of the
    relation as you suggest but I still have the same problem:
    INSERT INTO ANAG(ID_ANAG) VALUES (2088176453)
    INSERT INTO INDI(ID_INDI, ID_ENTITA) VALUES (2088176453, NULL)
    while I expect
    INSERT INTO ANAG(ID_ANAG) VALUES (2088176453)
    INSERT INTO INDI(ID_INDI, ID_ENTITA) VALUES (<some ID>, 2088176453)
    any ideas?
    regards

  • One-to-many relation sometimes INSERTs child before parent

    Hi,
    I have a one-to-many relationship, say Company-Employee, that I want to be
    managed by the parent entity (Company), so that when I make persistent the
    Company, its Employees are also made persistent, and when I delete the
    Company, its Employees are deleted. In my Java code, Company has an
    ArrayList of Employees, and Employee has a Company member variable.
    My metadata looks like this:
    <class name="Company" identity-type="application">...
         <field name="employees">
              <collection element-type="Employee"/>
              <extension vendor-name="kodo" key="inverse-owner" value="company"/>
              <!-- delete all Employees when the Company is deleted -->
              <extension vendor-name="kodo" key="element-dependent" value="true"/>
         </field>
    </class>
    <class name="Employee" identity-type="application">...
         <field name="company"/>
    </class>
    I have a test that is creating a Company with an Employee and persisting
    it. It then deletes the Company. The test is passing some of the time and
    failing some of the time. It seems to not be consistent with the ordering
    of the INSERTs - sometimes it inserts Company then Employee, but sometimes
    it first tries to insert into Employee, which fails with a foreign key
    constraint to the parent table.
    How can I force it to insert into the parent table first?
    I notice that the documentation says you need the field of the child
    entity to be the inverse-owner. Is it not possible for the parent entity
    to own the relationship?
    Many thanks,
    Alex

    Alex,
    If you have non-deferred foreign keys between the tables, and you turn
    on Kodo's foreign key reordering algorithm, Kodo will ensure that all
    your foreign key constraints are met, regardless of the ordering of the
    operations in your Java code.
    See http://docs.solarmetric.com/ref_guide_dbsetup_fks.html for details
    about this.
    Regarding inverse-owner specification -- is there any reason why you
    want to specify this on the other side? inverse-owner basically defines
    which side of a shared relationship defines the mappings and should be
    monitored for changes; it does not have any impact on the mappings
    themselves.
    -Patrick
    Alex Robbins wrote:
    Hi,
    I have a one-to-many relationship, say Company-Employee, that I want to be
    managed by the parent entity (Company), so that when I make persistent the
    Company, its Employees are also made persistent, and when I delete the
    Company, its Employees are deleted. In my Java code, Company has an
    ArrayList of Employees, and Employee has a Company member variable.
    My metadata looks like this:
    <class name="Company" identity-type="application">...
         <field name="employees">
              <collection element-type="Employee"/>
              <extension vendor-name="kodo" key="inverse-owner" value="company"/>
              <!-- delete all Employees when the Company is deleted -->
              <extension vendor-name="kodo" key="element-dependent" value="true"/>
         </field>
    </class>
    <class name="Employee" identity-type="application">...
         <field name="company"/>
    </class>
    I have a test that is creating a Company with an Employee and persisting
    it. It then deletes the Company. The test is passing some of the time and
    failing some of the time. It seems to not be consistent with the ordering
    of the INSERTs - sometimes it inserts Company then Employee, but sometimes
    it first tries to insert into Employee, which fails with a foreign key
    constraint to the parent table.
    How can I force it to insert into the parent table first?
    I notice that the documentation says you need the field of the child
    entity to be the inverse-owner. Is it not possible for the parent entity
    to own the relationship?
    Many thanks,
    Alex

  • Unable to read one-to-many relations using Hibernate

    Hi,
    I am trying with a very simple one-to-many relationship. When I am storing the objects, there are no problems. But when I am trying to read out the collection, it says invalid descriptor index. Please help.
    Regards,
    Hibernate version:
    hibernate-3.1rc2
    Mapping documents:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
         <class name="Parent">
              <id name="id">
                   <generator class="identity"/>
              </id>
              <set name="children">
                   <key column="parent_id"/>
                   <one-to-many class="Child"/>
              </set>
         </class>
         <class name="Child">
              <id name="id">
                   <generator class="identity"/>
              </id>
              <property name="name"/>
         </class>
    </hibernate-mapping>
    Code between sessionFactory.openSession() and session.close():
    The Parent class:
    public class Parent
         private Long id ;     
         private Set children;
         Parent(){}
         public Long getId()
              return id;
         public void setId(Long id)
              this.id=id;
         public Set getChildren()
              return children;
         public void setChildren(Set children)
              this.children=children;
    The Child class:
    public class Child
         private Long id;
         private String name;
         Child(){}
         public Long getId()
              return id;
         private void setId(Long id)
              this.id=id;
         public String getName()
              return name;
         public void setName(String name)
              this.name=name;
    The Main class:
    public class PCManager
         public static void main(String[] args)
              PCManager mgr = new PCManager();
              List lt = null;
              if (args[0].equals("store"))
                   mgr.createAndStoreParent(new HashSet(3));
              else if (args[0].equals("list"))
                   mgr.listEvents();
              HibernateUtil.getSessionFactory().close();
         private void createAndStoreParent(HashSet s)
              HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
              Parent p1 = new Parent();
              int size = 3;
              for (int i=size; i>0; i--)
                   Child c = new Child();
                   c.setName("Child"+i);
                   s.add(c);
              p1.setChildren (s);
              Iterator elems = s.iterator();
              do {     
                   Child ch = (Child) elems.next();
                   HibernateUtil.getSessionFactory().getCurrentSession().save(ch);
              }while(elems.hasNext());
              HibernateUtil.getSessionFactory().getCurrentSession().save(p1);
              HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
         private void listEvents()
              HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
              Parent result = (Parent) HibernateUtil.getSessionFactory().getCurrentSession().load(Parent.class, new Long(1));
              System.out.println("Id is :"+ result.getId());
              Set children = result.getChildren();
              Iterator elems = children.iterator();
              do {     
                   Child ch = (Child) elems.next();
                   System.out.println("Child Name"+ ch.getName());
              }while(elems.hasNext());
              HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();          
    Full stack trace of any exception that occurs:
    When I run with "hbm2ddl.auto" property as validate and trying to list the contents, I get the following out put.
    C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc2\MyHibernate>ant run -Da
    ction=list
    Buildfile: build.xml
    clean:
    [delete] Deleting directory C:\Documents and Settings\mirza\Desktop\hibernate
    -3.1rc2\MyHibernate\bin
    [mkdir] Created dir: C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc
    2\MyHibernate\bin
    copy-resources:
    [copy] Copying 4 files to C:\Documents and Settings\mirza\Desktop\hibernate
    -3.1rc2\MyHibernate\bin
    compile:
    [javac] Compiling 5 source files to C:\Documents and Settings\mirza\Desktop\
    hibernate-3.1rc2\MyHibernate\bin
    run:
    [java] 09:09:23,433 INFO Environment:474 - Hibernate 3.1 rc2
    [java] 09:09:23,449 INFO Environment:489 - loaded properties from resource
    hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate
    .cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.dial
    ect=org.hibernate.dialect.SQLServerDialect, hibernate.max_fetch_depth=1, hiberna
    te.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.
    substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.cac
    he.region_prefix=hibernate.test, hibernate.jdbc.batch_versioned_data=true, hiber
    nate.connection.pool_size=1}
    [java] 09:09:23,465 INFO Environment:519 - using java.io streams to persis
    t binary types
    [java] 09:09:23,465 INFO Environment:520 - using CGLIB reflection optimize
    r
    [java] 09:09:23,481 INFO Environment:550 - using JDK 1.4 java.sql.Timestam
    p handling
    [java] 09:09:23,559 INFO Configuration:1257 - configuring from resource: /
    hibernate.cfg.xml
    [java] 09:09:23,559 INFO Configuration:1234 - Configuration resource: /hib
    ernate.cfg.xml
    [java] 09:09:23,872 INFO Configuration:460 - Reading mappings from resourc
    e: PCMapping.hbm.xml
    [java] 09:09:24,013 INFO HbmBinder:266 - Mapping class: Parent -> Parent
    [java] 09:09:24,045 INFO HbmBinder:266 - Mapping class: Child -> Child
    [java] 09:09:24,045 INFO Configuration:1368 - Configured SessionFactory: n
    ull
    [java] 09:09:24,061 INFO Configuration:1014 - processing extends queue
    [java] 09:09:24,061 INFO Configuration:1018 - processing collection mappin
    gs
    [java] 09:09:24,061 INFO HbmBinder:2233 - Mapping collection: Parent.child
    ren -> Child
    [java] 09:09:24,076 INFO Configuration:1027 - processing association prope
    rty references
    [java] 09:09:24,076 INFO Configuration:1049 - processing foreign key const
    raints
    [java] 09:09:24,155 INFO DriverManagerConnectionProvider:41 - Using Hibern
    ate built-in connection pool (not for production use!)
    [java] 09:09:24,170 INFO DriverManagerConnectionProvider:42 - Hibernate co
    nnection pool size: 1
    [java] 09:09:24,170 INFO DriverManagerConnectionProvider:45 - autocommit m
    ode: false
    [java] 09:09:24,170 INFO DriverManagerConnectionProvider:80 - using driver
    : sun.jdbc.odbc.JdbcOdbcDriver at URL: jdbc:odbc:MySQL
    [java] 09:09:24,170 INFO DriverManagerConnectionProvider:86 - connection p
    roperties: {}
    [java] 09:09:24,264 INFO SettingsFactory:77 - RDBMS: Microsoft SQL Server,
    version: 08.00.0194
    [java] 09:09:24,264 INFO SettingsFactory:78 - JDBC driver: JDBC-ODBC Bridg
    e (SQLSRV32.DLL), version: 2.0001 (03.85.1117)
    [java] 09:09:24,296 INFO Dialect:100 - Using dialect: org.hibernate.dialec
    t.SQLServerDialect
    [java] 09:09:24,311 INFO TransactionFactoryFactory:31 - Using default tran
    saction strategy (direct JDBC transactions)
    [java] 09:09:24,327 INFO TransactionManagerLookupFactory:33 - No Transacti
    onManagerLookup configured (in JTA environment, use of read-write or transaction
    al second-level cache is not recommended)
    [java] 09:09:24,327 INFO SettingsFactory:125 - Automatic flush during befo
    reCompletion(): disabled
    [java] 09:09:24,327 INFO SettingsFactory:129 - Automatic session close at
    end of transaction: disabled
    [java] 09:09:24,343 INFO SettingsFactory:144 - Scrollable result sets: ena
    bled
    [java] 09:09:24,343 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): d
    isabled
    [java] 09:09:24,343 INFO SettingsFactory:160 - Connection release mode: au
    to
    [java] 09:09:24,358 INFO SettingsFactory:184 - Maximum outer join fetch de
    pth: 1
    [java] 09:09:24,358 INFO SettingsFactory:187 - Default batch fetch size: 1
    [java] 09:09:24,358 INFO SettingsFactory:191 - Generate SQL with comments:
    disabled
    [java] 09:09:24,358 INFO SettingsFactory:195 - Order SQL updates by primar
    y key: disabled
    [java] 09:09:24,358 INFO SettingsFactory:338 - Query translator: org.hiber
    nate.hql.ast.ASTQueryTranslatorFactory
    [java] 09:09:24,374 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTran
    slatorFactory
    [java] 09:09:24,374 INFO SettingsFactory:203 - Query language substitution
    s: {no='N', yes='Y'}
    [java] 09:09:24,374 INFO SettingsFactory:209 - Second-level cache: enabled
    [java] 09:09:24,374 INFO SettingsFactory:213 - Query cache: disabled
    [java] 09:09:24,374 INFO SettingsFactory:325 - Cache provider: org.hiberna
    te.cache.HashtableCacheProvider
    [java] 09:09:24,374 INFO SettingsFactory:228 - Optimize cache for minimal
    puts: disabled
    [java] 09:09:24,374 INFO SettingsFactory:233 - Cache region prefix: hibern
    ate.test
    [java] 09:09:24,405 INFO SettingsFactory:237 - Structured second-level cac
    he entries: disabled
    [java] 09:09:24,437 INFO SettingsFactory:257 - Echoing all SQL to stdout
    [java] 09:09:24,452 INFO SettingsFactory:264 - Statistics: disabled
    [java] 09:09:24,452 INFO SettingsFactory:268 - Deleted entity synthetic id
    entifier rollback: disabled
    [java] 09:09:24,452 INFO SettingsFactory:283 - Default entity-mode: POJO
    [java] 09:09:24,593 INFO SessionFactoryImpl:155 - building session factory
    [java] 09:09:24,938 INFO SessionFactoryObjectFactory:82 - Not binding fact
    ory to JNDI, no JNDI name configured
    [java] 09:09:24,954 INFO SchemaValidator:99 - Running schema validator
    [java] 09:09:24,954 INFO SchemaValidator:107 - fetching database metadata
    [java] 09:09:24,954 INFO Configuration:1014 - processing extends queue
    [java] 09:09:24,954 INFO Configuration:1018 - processing collection mappin
    gs
    [java] 09:09:24,954 INFO Configuration:1027 - processing association prope
    rty references
    [java] 09:09:24,954 INFO Configuration:1049 - processing foreign key const
    raints
    [java] 09:09:24,985 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState
    : S1002
    [java] 09:09:24,985 ERROR JDBCExceptionReporter:72 - [Microsoft][ODBC SQL S
    erver Driver]Invalid Descriptor Index
    [java] 09:09:25,001 ERROR SchemaValidator:129 - Error closing connection
    [java] java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid transaction state
    [java] Initial SessionFactory creation failed.org.hibernate.exception.Gener
    icJDBCException: could not get table metadata: Child
    [java] java.lang.ExceptionInInitializerError
    [java] at HibernateUtil.<clinit>(Unknown Source)
    [java] at PCManager.listEvents(Unknown Source)
    [java] at PCManager.main(Unknown Source)
    [java] Caused by: org.hibernate.exception.GenericJDBCException: could not g
    et table metadata: Child
    [java] at org.hibernate.exception.SQLStateConverter.handledNonSpecificE
    xception(SQLStateConverter.java:91)
    [java] at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)
    [java] at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
    [java] at sun.jdbc.odbc.JdbcOdbc.SQLDisconnect(JdbcOdbc.java:2988)
    [java] at sun.jdbc.odbc.JdbcOdbcDriver.disconnect(JdbcOdbcDriver.java:9
    80)
    [java] at sun.jdbc.odbc.JdbcOdbcConnection.close(JdbcOdbcConnection.jav
    a:739)
    [java] at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaVal
    idator.java:125)
    [java] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryIm
    pl.java:299)
    [java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
    tion.java:1145)
    [java] at HibernateUtil.<clinit>(Unknown Source)
    [java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateCon
    verter.java:79)
    [java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
    tionHelper.java:43)
    [java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
    tionHelper.java:29)
    [java] at org.hibernate.tool.hbm2ddl.DatabaseMetadata.getTableMetadata(
    DatabaseMetadata.java:100)
    [java] at org.hibernate.cfg.Configuration.validateSchema(Configuration.
    java:946)
    [java] at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaVal
    idator.java:116)
    [java] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryIm
    pl.java:299)
    [java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
    tion.java:1145)
    [java] ... 3 more
    [java] Caused by: java.sql.SQLException: [Microsoft][ODBC SQL Server Driver
    ]Invalid Descriptor Index
    [java] at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6879)
    [java] at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7036)
    [java] at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3862)
    [java] at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultS
    et.java:5561)
    [java] at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.j
    ava:338)
    [java] at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.j
    ava:395)
    [java] at PCManager.listEvents(Unknown Source)
    [java] at PCManager.main(Unknown Source)
    [java] at org.hibernate.tool.hbm2ddl.TableMetadata.<init>(TableMetadata
    .java:30)
    [java] at org.hibernate.tool.hbm2ddl.DatabaseMetadata.getTableMetadata(
    DatabaseMetadata.java:85)
    [java] ... 7 more
    [java] Exception in thread "main"
    [java] Java Result: 1
    BUILD SUCCESSFUL
    Total time: 4 seconds
    Name and version of the database you are using:
    Microsoft SQLServer2000
    The generated SQL (show_sql=true):
    When the program is run with "hbm2ddl.auto" property as create, I get the following output.
    C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc2\MyHibernate>ant run -Daction=store
    Buildfile: build.xml
    clean:
    [delete] Deleting directory C:\Documents and Settings\mirza\Desktop\hibernate
    -3.1rc2\MyHibernate\bin
    [mkdir] Created dir: C:\Documents and Settings\mirza\Desktop\hibernate-3.1rc
    2\MyHibernate\bin
    copy-resources:
    [copy] Copying 4 files to C:\Documents and Settings\mirza\Desktop\hibernate
    -3.1rc2\MyHibernate\bin
    compile:
    [javac] Compiling 5 source files to C:\Documents and Settings\mirza\Desktop\
    hibernate-3.1rc2\MyHibernate\bin
    run:
    [java] 09:12:54,820 INFO Environment:474 - Hibernate 3.1 rc2
    [java] 09:12:54,836 INFO Environment:489 - loaded properties from resource
    hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate
    .cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.dial
    ect=org.hibernate.dialect.SQLServerDialect, hibernate.max_fetch_depth=1, hiberna
    te.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.
    substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.cac
    he.region_prefix=hibernate.test, hibernate.jdbc.batch_versioned_data=true, hiber
    nate.connection.pool_size=1}
    [java] 09:12:54,852 INFO Environment:519 - using java.io streams to persis
    t binary types
    [java] 09:12:54,852 INFO Environment:520 - using CGLIB reflection optimize
    r
    [java] 09:12:54,867 INFO Environment:550 - using JDK 1.4 java.sql.Timestam
    p handling
    [java] 09:12:54,946 INFO Configuration:1257 - configuring from resource: /
    hibernate.cfg.xml
    [java] 09:12:54,946 INFO Configuration:1234 - Configuration resource: /hib
    ernate.cfg.xml
    [java] 09:12:55,259 INFO Configuration:460 - Reading mappings from resourc
    e: PCMapping.hbm.xml
    [java] 09:12:55,400 INFO HbmBinder:266 - Mapping class: Parent -> Parent
    [java] 09:12:55,447 INFO HbmBinder:266 - Mapping class: Child -> Child
    [java] 09:12:55,447 INFO Configuration:1368 - Configured SessionFactory: n
    ull
    [java] 09:12:55,447 INFO Configuration:1014 - processing extends queue
    [java] 09:12:55,447 INFO Configuration:1018 - processing collection mappin
    gs
    [java] 09:12:55,447 INFO HbmBinder:2233 - Mapping collection: Parent.child
    ren -> Child
    [java] 09:12:55,463 INFO Configuration:1027 - processing association prope
    rty references
    [java] 09:12:55,479 INFO Configuration:1049 - processing foreign key const
    raints
    [java] 09:12:55,557 INFO DriverManagerConnectionProvider:41 - Using Hibern
    ate built-in connection pool (not for production use!)
    [java] 09:12:55,557 INFO DriverManagerConnectionProvider:42 - Hibernate co
    nnection pool size: 1
    [java] 09:12:55,557 INFO DriverManagerConnectionProvider:45 - autocommit m
    ode: false
    [java] 09:12:55,573 INFO DriverManagerConnectionProvider:80 - using driver
    : sun.jdbc.odbc.JdbcOdbcDriver at URL: jdbc:odbc:MySQL
    [java] 09:12:55,573 INFO DriverManagerConnectionProvider:86 - connection p
    roperties: {}
    [java] 09:12:55,651 INFO SettingsFactory:77 - RDBMS: Microsoft SQL Server,
    version: 08.00.0194
    [java] 09:12:55,667 INFO SettingsFactory:78 - JDBC driver: JDBC-ODBC Bridg
    e (SQLSRV32.DLL), version: 2.0001 (03.85.1117)
    [java] 09:12:55,682 INFO Dialect:100 - Using dialect: org.hibernate.dialec
    t.SQLServerDialect
    [java] 09:12:55,698 INFO TransactionFactoryFactory:31 - Using default tran
    saction strategy (direct JDBC transactions)
    [java] 09:12:55,714 INFO TransactionManagerLookupFactory:33 - No Transacti
    onManagerLookup configured (in JTA environment, use of read-write or transaction
    al second-level cache is not recommended)
    [java] 09:12:55,714 INFO SettingsFactory:125 - Automatic flush during befo
    reCompletion(): disabled
    [java] 09:12:55,714 INFO SettingsFactory:129 - Automatic session close at
    end of transaction: disabled
    [java] 09:12:55,729 INFO SettingsFactory:144 - Scrollable result sets: ena
    bled
    [java] 09:12:55,729 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): d
    isabled
    [java] 09:12:55,745 INFO SettingsFactory:160 - Connection release mode: au
    to
    [java] 09:12:55,745 INFO SettingsFactory:184 - Maximum outer join fetch de
    pth: 1
    [java] 09:12:55,745 INFO SettingsFactory:187 - Default batch fetch size: 1
    [java] 09:12:55,745 INFO SettingsFactory:191 - Generate SQL with comments:
    disabled
    [java] 09:12:55,745 INFO SettingsFactory:195 - Order SQL updates by primar
    y key: disabled
    [java] 09:12:55,745 INFO SettingsFactory:338 - Query translator: org.hiber
    nate.hql.ast.ASTQueryTranslatorFactory
    [java] 09:12:55,777 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTran
    slatorFactory
    [java] 09:12:55,792 INFO SettingsFactory:203 - Query language substitution
    s: {no='N', yes='Y'}
    [java] 09:12:55,792 INFO SettingsFactory:209 - Second-level cache: enabled
    [java] 09:12:55,792 INFO SettingsFactory:213 - Query cache: disabled
    [java] 09:12:55,792 INFO SettingsFactory:325 - Cache provider: org.hiberna
    te.cache.HashtableCacheProvider
    [java] 09:12:55,808 INFO SettingsFactory:228 - Optimize cache for minimal
    puts: disabled
    [java] 09:12:55,808 INFO SettingsFactory:233 - Cache region prefix: hibern
    ate.test
    [java] 09:12:55,808 INFO SettingsFactory:237 - Structured second-level cac
    he entries: disabled
    [java] 09:12:55,839 INFO SettingsFactory:257 - Echoing all SQL to stdout
    [java] 09:12:55,839 INFO SettingsFactory:264 - Statistics: disabled
    [java] 09:12:55,839 INFO SettingsFactory:268 - Deleted entity synthetic id
    entifier rollback: disabled
    [java] 09:12:55,839 INFO SettingsFactory:283 - Default entity-mode: POJO
    [java] 09:12:55,980 INFO SessionFactoryImpl:155 - building session factory
    [java] 09:12:56,325 INFO SessionFactoryObjectFactory:82 - Not binding fact
    ory to JNDI, no JNDI name configured
    [java] 09:12:56,341 INFO Configuration:1014 - processing extends queue
    [java] 09:12:56,341 INFO Configuration:1018 - processing collection mappin
    gs
    [java] 09:12:56,341 INFO Configuration:1027 - processing association prope
    rty references
    [java] 09:12:56,341 INFO Configuration:1049 - processing foreign key const
    raints
    [java] 09:12:56,356 INFO Configuration:1014 - processing extends queue
    [java] 09:12:56,356 INFO Configuration:1018 - processing collection mappin
    gs
    [java] 09:12:56,356 INFO Configuration:1027 - processing association prope
    rty references
    [java] 09:12:56,372 INFO Configuration:1049 - processing foreign key const
    raints
    [java] 09:12:56,372 INFO SchemaExport:153 - Running hbm2ddl schema export
    [java] 09:12:56,388 DEBUG SchemaExport:171 - import file not found: /import
    .sql
    [java] 09:12:56,388 INFO SchemaExport:180 - exporting generated schema to
    database
    [java] 09:12:56,403 DEBUG SchemaExport:283 -
    [java] alter table Child
    [java] drop constraint FK3E104FC976A59A
    [java] 09:12:56,466 DEBUG SchemaExport:283 -
    [java] drop table Child
    [java] 09:12:56,544 DEBUG SchemaExport:283 -
    [java] drop table Parent
    [java] 09:12:56,654 DEBUG SchemaExport:283 -
    [java] create table Child (
    [java] id numeric(19,0) identity not null,
    [java] name varchar(255) null,
    [java] parent_id numeric(19,0) null,
    [java] primary key (id)
    [java] )
    [java] 09:12:56,779 DEBUG SchemaExport:283 -
    [java] create table Parent (
    [java] id numeric(19,0) identity not null,
    [java] primary key (id)
    [java] )
    [java] 09:12:56,873 DEBUG SchemaExport:283 -
    [java] alter table Child
    [java] add constraint FK3E104FC976A59A
    [java] foreign key (parent_id)
    [java] references Parent
    [java] 09:12:56,952 INFO SchemaExport:200 - schema export complete
    [java] 09:12:56,952 WARN JDBCExceptionReporter:48 - SQL Warning: 5701, SQL
    State: 01000
    [java] 09:12:56,952 WARN JDBCExceptionReporter:49 - [Microsoft][ODBC SQL S
    erver Driver][SQL Server]Changed database context to 'master'.
    [java] 09:12:56,952 WARN JDBCExceptionReporter:48 - SQL Warning: 5703, SQL
    State: 01000
    [java] 09:12:56,952 WARN JDBCExceptionReporter:49 - [Microsoft][ODBC SQL S
    erver Driver][SQL Server]Changed language setting to us_english.
    [java] 09:12:56,983 INFO SessionFactoryImpl:432 - Checking 0 named queries
    [java] Hibernate:
    [java] insert
    [java] into
    [java] Child
    [java] (name)
    [java] values
    [java] (?) select
    [java] scope_identity()
    [java] Hibernate:
    [java] insert
    [java] into
    [java] Child
    [java] (name)
    [java] values
    [java] (?) select
    [java] scope_identity()
    [java] Hibernate:
    [java] insert
    [java] into
    [java] Child
    [java] (name)
    [java] values
    [java] (?) select
    [java] scope_identity()
    [java] Hibernate:
    [java] insert
    [java] into
    [java] Parent
    [java] default
    [java] values
    [java] select
    [java] scope_identity()
    [java] Hibernate:
    [java] update
    [java] Child
    [java] set
    [java] parent_id=?
    [java] where
    [java] id=?
    [java] Hibernate:
    [java] update
    [java] Child
    [java] set
    [java] parent_id=?
    [java] where
    [java] id=?
    [java] Hibernate:
    [java] update
    [java] Child
    [java] set
    [java] parent_id=?
    [java] where
    [java] id=?
    [java] 09:12:57,390 INFO SessionFactoryImpl:831 - closing
    [java] 09:12:57,390 INFO DriverManagerConnectionProvider:147 - cleaning up
    connection pool: jdbc:odbc:MySQL
    BUILD SUCCESSFUL
    Total time: 5 seconds
    Debug level Hibernate log excerpt:
    Included in the above description.

    That's not the right mapping for the 1:m relationship in Hibernate.
    First of all, I believe the recommendation is to have a separate .hbm.xml file for each class, so you should have one for Parent and Child.
    Second, you'll find the proper syntax for a one-to-many relationship here:
    http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html#tutorial-associations
    See if those help.
    The tutorial docs for Hibernate are quite good. I'd recommend going through them carefully.
    %

  • Cant't get one to many relation to work.

    I tried to without success to retrieve an object that represents a simple
    parent child relation in an existing database. (the object is supposed to
    represent one record of the parent table and contain a Collection of all
    records in the child table)
    I have these two tables:
    table "refrul" is the parent table (column "nr" is the primary key)
    table "reftab" is the child (column "refundrule" points to refrul.nr)
    This is my .jdo file
    <?xml version="1.0"?>
    <jdo>
    <package name="jdbctest">
    <class name="RefundRule" objectid-class="RefundRuleId">
    <extension vendor-name="kodo" key="table" value="refrul"/>
    <extension vendor-name="kodo" key="lock-column" value="none"/>
    <extension vendor-name="kodo" key="class-column" value="none"/>
    <field name="ruleNr" primary-key="true">
    <extension vendor-name="kodo" key="data-column" value="nr"/>
    </field>
    <field name="ruleName">
    <extension vendor-name="kodo" key="data-column"
    value="name"/>
    </field>
    <field name="minSalesAmount">
    <extension vendor-name="kodo" key="data-column"
    value="minsalesamount"/>
    </field>
    <field name="refundTable">
    <collection element-type="RefundTableRow"/>
    <extension vendor-name="kodo" key="table" value="reftab"/>
    <extension vendor-name="kodo" key="ruleNr-ref-column"
    value="refundrule"/>
    </field>
    </class>
    <class name="RefundTableRow" objectid-class="RefundTableRowId">
    <extension vendor-name="kodo" key="table" value="reftab"/>
    <extension vendor-name="kodo" key="lock-column" value="none"/>
    <extension vendor-name="kodo" key="class-column" value="none"/>
    <field name="ruleNr" primary-key="true">
    <extension vendor-name="kodo" key="data-column"
    value="refundrule"/>
    </field>
    <field name="vatRate" primary-key="true">
    <extension vendor-name="kodo" key="data-column"
    value="ustsatz"/>
    </field>
    <field name="fromSalesAmount" primary-key="true">
    <extension vendor-name="kodo" key="data-column"
    value="ab_betrag"/>
    </field>
    <field name="refundPercent">
    <extension vendor-name="kodo" key="data-column"
    value="refund_prozent"/>
    </field>
    <field name="refundAmount">
    <extension vendor-name="kodo" key="data-column"
    value="refund_betrag"/>
    </field>
    </class>
    </package>
    </jdo>
    I get an exception showing this query:
    [SQL=SELECT t0.ab_betrag, t0.refundrule, t0.ustsatz, t0.refund_betrag,
    t0.refund_prozent, t0.RULENAMEX
    FROM reftab t0 WHERE(t0.refundrule = 0 AND t0.ab_betrag =
    t0.FROMSALESAMOUNT_REFUNDTABLEX AND t0.refundrule = t0.RULENR_REFUNDTABLEX
    AND t0.ustsatz = t0.VATRATE_REFUNDTABLEX)]
    All columns in uppercase do not exist in my tables, so this must generate an
    exception.
    Also the join seems strange I would have expected only " ...
    WHERE(t0.refundrule = parenttableRuleNr)".
    Whats wrong?
    I am using kodo 2.3
    Regards,
    Bernhard

    Abe,
    the strange column names are gone now, but it still does not work
    This is my new .jdo file (Iadded the "inverse" line)
    <?xml version="1.0"?>
    <jdo>
    <package name="jdbctest">
    <class name="RefundRule" objectid-class="RefundRuleId">
    <extension vendor-name="kodo" key="table" value="refrul"/>
    <extension vendor-name="kodo" key="lock-column" value="none"/>
    <extension vendor-name="kodo" key="class-column" value="none"/>
    <field name="ruleNr" primary-key="true">
    <extension vendor-name="kodo" key="data-column" value="nr"/>
    </field>
    <field name="ruleName">
    <extension vendor-name="kodo" key="data-column"
    value="name"/>
    </field>
    <field name="minSalesAmount">
    <extension vendor-name="kodo" key="data-column"
    value="minsalesamount"/>
    </field>
    <field name="refundStep">
    <extension vendor-name="kodo" key="data-column"
    value="refundstep"/>
    </field>
    <field name="refundTable">
    <collection element-type="RefundTableRow"/>
    <extension vendor-name="kodo" key="table" value="reftab"/>
    <extension vendor-name="kodo" key="ruleNr-ref-column"
    value="refundrule"/>
    <extension vendor-name="kodo" key="inverse" value="ruleNr"/>
    </field>
    </class>
    <class name="RefundTableRow" objectid-class="RefundTableRowId">
    <extension vendor-name="kodo" key="table" value="reftab"/>
    <extension vendor-name="kodo" key="lock-column" value="none"/>
    <extension vendor-name="kodo" key="class-column" value="none"/>
    <field name="ruleNr" primary-key="true">
    <extension vendor-name="kodo" key="data-column"
    value="refundrule"/>
    </field>
    <field name="vatRate" primary-key="true">
    <extension vendor-name="kodo" key="data-column"
    value="ustsatz"/>
    </field>
    <field name="fromSalesAmount" primary-key="true">
    <extension vendor-name="kodo" key="data-column"
    value="ab_betrag"/>
    </field>
    <field name="refundPercent">
    <extension vendor-name="kodo" key="data-column"
    value="refund_prozent"/>
    </field>
    <field name="refundAmount">
    <extension vendor-name="kodo" key="data-column"
    value="refund_betrag"/>
    </field>
    </class>
    </package>
    </jdo>
    This the generated SQL:
    [SQL=SELECT t0.nr, t0.minsalesamount, t0.refundstep, t0.name FROM refrul t0,
    reftab t1 WHERE (t0.nr = t1.nr)]
    This throws an exception because t1.nr (reftab.nr) does not exist, it should
    be reftab.refundrule. This would be correct:
    SELECT t0.nr, t0.minsalesamount, t0.refundstep, t0.name FROM refrul t0,
    reftab t1 WHERE (t0.nr = t1.refundrule)]
    Regards,
    Bernhard

  • How to handle One to Many relation In BI Data Model

    Hi,
    I posted this same question earlier but bit in a different way ..
    I have may be infact many come across this requirement ..
    As you know R3 Multiple Partner functions would be assigned to a single Sales document but when we want to show the same sales report along with Sales document and respective partner functions in BI it is bit difficult because we can not really allow to split the keyfigure values based on Partner functions when they drilled down by Pfunctions ...
    Only alternative is to have multiple partner function attributes (columns) like one for each pfunction in one of the Sales Doc Masterdata and define them as navigational attributes..so that all partner functions would be saved
    SALES DOC -
    PartnerFunction-----AMOUNT
    100000----
       ZZ -
    5000
    100000--   AB--
    100000--    BC--
    to meet above requirement as per my above proposed alternative looks like as below
    SALES DOC -
    Partner Function 1--PArtner Function2-- PF3------ AMOUNT
    100000--ZZABBC--
    5000
    So other than this do you see any other better Data Model ??
    Could you please share your thoughts on it??
    Thanks & Regards,
    BRK

    Create a view based on VBPA ( Sales partner functions) and VBAK,VBAPor VBEP ( anyone relevant to your case) and create a generic datasource based on that

  • Delete few child objects of One to Many relation.

    Hi
    we have the follwoing relation. Employee -> Addresses
    One employe is having 5 addresses.
    Now we need to delete 2 addresses for this employee.
    Can any one suggest the best way to do this in my java program.
    regards
    Ram kumar

    Are you using JPA or the native TopLink API?
    Either remove them from the Employee then call deleteObject/remove on them. Or mark the relationship as privateOwned in TopLink and just remove them.
    -- James : http://www.eclipselink.org

  • SharePoint List (one to many Relation)

    Hi,
    I have a word document which I am suppose to convert as the custom List. 
    Everything is going fine till the time i got a table inside the word document which i am suppose to convert as the List Column.
    I have no idea how do i convert the same into custom list columns.
    PS: I have already tried convincing the customer to use the Document library and document templates but they do not want it :(
    Thanks, Parth

    Hi,
    To read the content of the Word document and populated into SharePoint List, a solution can be like this: We can create a client desktop application to read the content of a
    Word document stores in local drive using Word Object Model, then add the wanted values to a SharePoint List using SharePoint Client Object Model.
    Working with Documents
    How to: Complete basic operations using SharePoint 2013 client
    library code
    Feel free to reply if there are still any questions.
    Best regards,
    Patrick
    Patrick Liang
    TechNet Community Support

  • Making a one to many relation it to columns per entry of the many relation

    CREATE TABLE main (id number, data varchar2(20));
    INSERT INTO main values (1,'some data1');
    INSERT INTO main values (2,'some data2');
    CREATE TABLE sub(main_id number, data varchar2(20), value number);
    INSERT INTO sub values (1,'data1', 10);
    INSERT INTO sub values (1,'data2', 5);
    INSERT INTO sub values (2,'data3', 10);
    INSERT INTO sub values (2,'data4', 30);
    INSERT INTO sub values (2,'data5', 20);
    I want a result like this
    id | data | sub1 | sub2 | sub3
    1, some data1, data1, data2, NULL
    2, some data2, data4, data5, data1
    That is sub1 is the value sub.data that has the largest value, sub2 is the second largest and so on.
    This is the closest I can get. Is there a way to make the where main_id = 1 dynamic so instead of 1 it refeers to the value of main.id? Or is there a different query that will give me the result I'm looking for?
    SELECT main.id, main.data, sub1.data sub1, sub2.data sub2, sub3.data sub3
    FROM main
    full outer join
    (SELECT main_id, data, value
    FROM(SELECT main_id, data, value, rownum rn
    FROM(SELECT *
    FROM sub
    WHERE main_id = 1
    ORDER BY value desc))
    WHERE rn = 1) sub1
    on main.id = sub1.main_id
    full outer join
    (SELECT main_id, data, value
    FROM(SELECT main_id, data, value, rownum rn
    FROM(SELECT *
    FROM sub
    WHERE main_id = 1
    ORDER BY value desc))
    WHERE rn = 2) sub2
    on main.id = sub2.main_id
    full outer join
    (SELECT main_id, data, value
    FROM(SELECT main_id, data, value, rownum rn
    FROM(SELECT *
    FROM sub
    WHERE main_id = 1
    ORDER BY value desc))
    WHERE rn = 3) sub3
    on main.id = sub3.main_id
    ID     DATA     SUB1     SUB2     SUB3
    2     some data2     -      -      -
    1     some data1     data1     data2     -

    SQL> select main.id
      2       , main.data
      3       , max(decode(sub.rn,1,sub.data)) "sub1"
      4       , max(decode(sub.rn,2,sub.data)) "sub2"
      5       , max(decode(sub.rn,3,sub.data)) "sub3"
      6    from main
      7       , (select t.*, row_number() over (partition by main_id order by data) rn from sub t) sub
      8   where sub.main_id = main.id
      9   group by main.id
    10       , main.data
    11  /
            ID DATA                 sub1                 sub2                 sub3
             1 some data1           data1                data2
             2 some data2           data3                data4                data5
    2 rijen zijn geselecteerd.Regards,
    Rob.

  • EJB relation One to Many - ClassCastException

    Hi !
    I created two CMP EJB entity Client and Address. There is a One to Many relation between them.
    When I deploy them on JBoss, I have no errors, and the correponding tables are created in the database. The EJB seems to work fine, but when I use a 'relation' method : myAddress.setClient(myClient) for instance. I get a ServerException.
    In the log of JBoss there is :
    ClassCastException : org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.SetInstanceValue(...)
    I think I have a problem in my descriptors or JBoss configuration.
    If u have an idea ...
    Thx

    sorry to whack a load of code in but i can't see where the problem is here is my ejb-jar.xml file:
    <ejb-jar>
         <enterprise-beans>
              <entity>
                   <description>This bean represents a copy item.</description>
                   <ejb-name>CopyEJB</ejb-name>
                   <home>com.RemoteCopyHome</home>
                   <remote>com.RemoteCopy</remote>
                   <local-home>com.LocalCopyHome</local-home>
                   <local>com.LocalCopy</local>
                   <ejb-class>com.CopyBean</ejb-class>
                   <persistence-type>Container</persistence-type>
                   <prim-key-class>java.lang.String</prim-key-class>
                   <reentrant>False</reentrant>
                   <cmp-version>2.x</cmp-version>
                   <abstract-schema-name>Copy</abstract-schema-name>
                   <cmp-field>
                        <field-name>copyid</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>quality</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>buyinprice</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>selloutprice</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>bookid</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>title</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>genre</field-name>
                   </cmp-field>
                   <primkey-field>copyid</primkey-field>
                   <security-identity>
                        <description></description>
                        <use-caller-identity></use-caller-identity>
                   </security-identity>
              </entity>
              <entity>
                   <description>This bean represents a supplier.</description>
                   <ejb-name>SupplierEJB</ejb-name>
                   <home>com.RemoteSupplierHome</home>
                   <remote>com.RemoteSupplier</remote>
                   <local-home>com.LocalSupplierHome</local-home>
                   <local>com.LocalSupplier</local>
                   <ejb-class>com.SupplierBean</ejb-class>
                   <persistence-type>Container</persistence-type>
                   <prim-key-class>java.lang.String</prim-key-class>
                   <reentrant>False</reentrant>
                   <cmp-version>2.x</cmp-version>
                   <abstract-schema-name>Supplier</abstract-schema-name>
                   <cmp-field>
                        <field-name>supplierid</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>name</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>address1</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>address2</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>address3</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>address4</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>postcode</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>email</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>telno</field-name>
                   </cmp-field>
                   <primkey-field>supplierid</primkey-field>
                   <security-identity>
                        <description></description>
                        <use-caller-identity></use-caller-identity>
                   </security-identity>
              </entity>
              <entity>
                   <description>This bean represents an edition.</description>
                   <ejb-name>EditionEJB</ejb-name>
                   <home>com.RemoteEditionHome</home>
                   <remote>com.RemoteEdition</remote>
                   <local-home>com.LocalEditionHome</local-home>
                   <local>com.LocalEdition</local>
                   <ejb-class>com.EditionBean</ejb-class>
                   <persistence-type>Container</persistence-type>
                   <prim-key-class>java.lang.String</prim-key-class>
                   <reentrant>False</reentrant>
                   <cmp-version>2.x</cmp-version>
                   <abstract-schema-name>Edition</abstract-schema-name>
                   <cmp-field>
                        <field-name>editionid</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>isbn</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>publisher</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>binding</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>other</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>edition</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>printdate</field-name>
                   </cmp-field>
                   <primkey-field>editionid</primkey-field>
                   <security-identity>
                        <description></description>
                        <use-caller-identity></use-caller-identity>
                   </security-identity>
              </entity>
              <entity>
                   <description>This bean represents an author.</description>
                   <ejb-name>AuthorEJB</ejb-name>
                   <home>com.RemoteAuthorHome</home>
                   <remote>com.RemoteAuthor</remote>
                   <local-home>com.LocalAuthorHome</local-home>
                   <local>com.LocalAuthor</local>
                   <ejb-class>com.AuthorBean</ejb-class>
                   <persistence-type>Container</persistence-type>
                   <prim-key-class>java.lang.String</prim-key-class>
                   <reentrant>False</reentrant>
                   <cmp-version>2.x</cmp-version>
                   <abstract-schema-name>Author</abstract-schema-name>
                   <cmp-field>
                        <field-name>authorid</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>name</field-name>
                   </cmp-field>
                   <primkey-field>authorid</primkey-field>
                   <security-identity>
                        <description></description>
                        <use-caller-identity></use-caller-identity>
                   </security-identity>
              </entity>
              <session>
                   <description>Supplier Function Session Bean</description>
                   <display-name>SupplierFunctionEJB</display-name>
                   <ejb-name>SupplierFunctionEJB</ejb-name>
                   <home>com.SupplierFunctionHome</home>
                   <remote>com.SupplierFunctionRemote</remote>
                   <ejb-class>com.SupplierFunctionSBean</ejb-class>
                   <session-type>Stateless</session-type>
                   <transaction-type>Container</transaction-type>
              </session>
              <session>
                   <description>Copy Function Session Bean</description>
                   <display-name>CopyFunctionEJB</display-name>
                   <ejb-name>CopyFunctionEJB</ejb-name>
                   <home>com.CopyFunctionHome</home>
                   <remote>com.CopyFunctionRemote</remote>
                   <ejb-class>com.CopyFunctionSBean</ejb-class>
                   <session-type>Stateless</session-type>
                   <transaction-type>Container</transaction-type>
              </session>
         </enterprise-beans>
         <relationships>
              <ejb-relation>
                   <ejb-relation-name>Supplier-Copy</ejb-relation-name>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>copy-recievedfrom-supplier</ejb-relationship-role-name>
                        <multiplicity>Many</multiplicity>
                        <cascade-delete></cascade-delete>
                        <relationship-role-source>
                             <ejb-name>CopyEJB</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                             <cmr-field-name>supplier</cmr-field-name>
                        </cmr-field>
                   </ejb-relationship-role>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>supplier-has-items</ejb-relationship-role-name>
                        <multiplicity>One</multiplicity>
                        <relationship-role-source>
                             <ejb-name>SupplierEJB</ejb-name>
                        </relationship-role-source>
                   </ejb-relationship-role>
              </ejb-relation>
              <ejb-relation>
                   <ejb-relation-name>Edition-Copy</ejb-relation-name>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>edition-has-items</ejb-relationship-role-name>
                        <multiplicity>One</multiplicity>
                        <relationship-role-source>
                             <ejb-name>EditionEJB</ejb-name>
                        </relationship-role-source>
                   </ejb-relationship-role>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>copy-is-a-edition</ejb-relationship-role-name>
                        <multiplicity>Many</multiplicity>
                        <cascade-delete></cascade-delete>
                        <relationship-role-source>
                             <ejb-name>CopyEJB</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                             <cmr-field-name>edition</cmr-field-name>
                        </cmr-field>
                   </ejb-relationship-role>
              </ejb-relation>
              <!--<ejb-relation>
                   <ejb-relation-name>Author-Copy</ejb-relation-name>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>copy-has-items</ejb-relationship-role-name>
                        <multiplicity>Many</multiplicity>                                     
        <relationship-role-source>
                             <ejb-name>AuthorEJB</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                             <cmr-field-name>copies</cmr-field-name>
                             <cmr-field-type>java.util.Set</cmr-field-type>
                        </cmr-field>
                   </ejb-relationship-role>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>copy-has-authors</ejb-relationship-role-name>
                        <multiplicity>Many</multiplicity>
                        <cascade-delete></cascade-delete>
                        <relationship-role-source>
                             <ejb-name>CopyEJB</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                             <cmr-field-name>authors</cmr-field-name>
                     <cmr-field-type>java.util.Set</cmr-field-type>     
                        </cmr-field>
                   </ejb-relationship-role>
              </ejb-relation>-->
         </relationships>
         <assembly-descriptor>
              <security-role>
                   <description>This role represents everyone who is allowed full access
             to the beans.</description>
                   <role-name>Subscribers</role-name>
              </security-role>
              <method-permission>
                   <role-name>Subscribers</role-name>
                   <method>
                        <ejb-name>CopyEJB</ejb-name>
                        <method-name>*</method-name>
                   </method>
                   <method>
                        <ejb-name>SupplierEJB</ejb-name>
                        <method-name>*</method-name>
                   </method>
              </method-permission>
              <container-transaction>
                   <method>
                        <ejb-name>CopyEJB</ejb-name>
                        <method-name>*</method-name>
                   </method>
                   <method>
                        <ejb-name>SupplierEJB</ejb-name>
                        <method-name>*</method-name>
                   </method>
                   <trans-attribute>Required</trans-attribute>
              </container-transaction>
         </assembly-descriptor>
    </ejb-jar>my session bean code can be found at
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=11&t=006578

Maybe you are looking for

  • Are Windows 7 and Elements 8 compatible?

    Just bought a Dell Windows 7 and reinstalled Elements 8  on it. When printing photos from elements to an HP k850 printer the results are terrible colors. Can anyone help re settings I should use in Elements. Tried Adobe color management and tried pri

  • How can i get and save the name of the file

    Hi all in my program i'm dealing with several text files each has its own name after doing some process on each i do save the output as output.txt can i add the file name before or after the output.txt i.e i want the name of the file to be part of th

  • How APEX work with New Schema

    Hello, I have APEX installed already in my database and currently it's catering 2 schemas, say schema1 and schema2. Schema2 has been dropped now and new Schema3 has been created. I changed dads.conf file and pointed to new schema, Schema3, restarted

  • Integrate two weblogic with LDAP embedded

    I need connect a weblogic with a LDAP embedded. I make the settings as follows: 1)Create a new provider of type LDAPAuthenticator. 2)The parameters  the provider are: <sec:authentication-provider xsi:type="wls:ldap-authenticatorType">         <sec:na

  • Change SY-UNAME

    i need to change the user name before calling a function module which releases an invoice frompayment block. actually scenario is a user will release the blocked invoice using the bapi BAPI_INCOMINGINVOICE_RELEASE. But he has no authorization to rele