facebook

Hibernate one-to-one generation

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #227203 Reply

    girikrishva
    Member

    I am using MyEclipse 3.8.4 to generate Hibernate mappings from an Oracle 9 database. I have two tables
    USERS (primary key is username)
    & REGISTRATIONS (primary key is username)
    & USERS.username is also foreign key to REGISTRATIONS.username.

    When I generate a mapping and execute a query like
    session.createQuery(“select users from miller.Users users”);
    I get an error like the one shown below:

    net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of miller.AbstractUsers.registrations…..etc.

    I have made no modifications to the default hibernate xml files generated by MyEclipse using te Database Explorer.

    Please help.

    #227209 Reply

    Riyad Kalla
    Member

    Can you post the schema for the tables and the generated hbm.xml files?

    #227211 Reply

    girikrishva
    Member

    USERS
    username varchar2(240) not null – PK
    email varchar2(240) not null
    active varchar2(1) not null
    created_on date not null
    updated_on date not null

    REGISTRATIONS
    username varchar2(240) not null – PK
    email varchar2(240) not null
    statusvarchar2(240) not null
    created_on date not null
    updated_on date not null

    FK relationship
    USERS.username (FK) to REGISTRATIONS.username

    hibernate.cfg.xml
    <?xml version=’1.0′ encoding=’UTF-8′?>
    <!DOCTYPE hibernate-configuration PUBLIC
    “-//Hibernate/Hibernate Configuration DTD 2.0//EN”
    http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd”&gt;

    <!– DO NOT EDIT: This is a generated file that is synchronized –>
    <!– by MyEclipse Hibernate tool integration. –>
    <hibernate-configuration>

    <session-factory>
    <!– properties –>
    <property name=”connection.username”>weblogic</property>
    <property name=”dialect”>net.sf.hibernate.dialect.Oracle9Dialect</property>
    <property name=”jndi.url”>t3://vhaishmul3:7003</property>
    <property name=”jndi.class”>weblogic.jndi.WLInitialContextFactory</property>
    <property name=”connection.datasource”>jdbc/jcpDS</property>
    <property name=”connection.password”>sanger2244</property>

    <!– mapping files –>
    <mapping resource=”limit/Registrations.hbm.xml”/>
    <mapping resource=”limit/Users.hbm.xml”/>

    </session-factory>

    </hibernate-configuration>

    users.hbm.xml
    <?xml version=”1.0″?>
    <!DOCTYPE hibernate-mapping PUBLIC
    “-//Hibernate/Hibernate Mapping DTD 2.0//EN”
    http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd&#8221; >

    <!– DO NOT EDIT: This is a generated file that is synchronized –>
    <!– by MyEclipse Hibernate tool integration. –>
    <!– Created Sat Mar 26 20:51:44 CST 2005 –>
    <hibernate-mapping package=”limit”>

    <class name=”Users” table=”USERS”>
    <id name=”username” column=”USERNAME” type=”java.lang.String”>
    <generator class=”assigned”/>
    </id>

    <property name=”email” column=”EMAIL” type=”java.lang.String” not-null=”true” />
    <property name=”active” column=”ACTIVE” type=”java.lang.String” not-null=”true” />
    <property name=”createdOn” column=”CREATED_ON” type=”java.util.Date” not-null=”true” />
    <property name=”updatedOn” column=”UPDATED_ON” type=”java.util.Date” not-null=”true” />
    <one-to-one name=”registrations” class=”Registrations”/>
    </class>

    </hibernate-mapping>

    registrations.hbm.xml
    <?xml version=”1.0″?>
    <!DOCTYPE hibernate-mapping PUBLIC
    “-//Hibernate/Hibernate Mapping DTD 2.0//EN”
    http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd&#8221; >

    <!– DO NOT EDIT: This is a generated file that is synchronized –>
    <!– by MyEclipse Hibernate tool integration. –>
    <!– Created Fri Mar 25 16:05:56 CST 2005 –>
    <hibernate-mapping package=”limit”>

    <class name=”Registrations” table=”REGISTRATIONS”>
    <id name=”username” column=”USERNAME” type=”java.lang.String”>
    <generator class=”assigned”/>
    </id>

    <property name=”email” column=”EMAIL” type=”java.lang.String” not-null=”true” />
    <property name=”status” column=”STATUS” type=”java.lang.String” not-null=”true” />
    <property name=”createdOn” column=”CREATED_ON” type=”java.util.Date” not-null=”true” />
    <property name=”updatedOn” column=”UPDATED_ON” type=”java.util.Date” not-null=”true” />
    </class>

    </hibernate-mapping>

    #227212 Reply

    Riyad Kalla
    Member

    Have you verified the “types” of the properties were translated correctly in the hbm.xml files to match up with the property types of your tables and on the classes?

    #227213 Reply

    girikrishva
    Member

    Yes

    #227220 Reply

    girikrishva
    Member

    Any progress please?

    #227228 Reply

    support-jeff
    Member

    You had to have touched the Users.hbm.xml file; ME does not currently support the generation of one-to-one relationships in the mapping file. What you need to do is define the o2o in *both* mapping files, and tell hibernate that Users PK is also a FK on Registrations by using the ‘constrained’ attribute of the o2o element:

    <class name="Registrations" table="REGISTRATIONS">
        <id name="username" column="USERNAME" type="java.lang.String">
            <generator class="assigned"/>
        </id>
        <property name="email" column="EMAIL" type="java.lang.String" not-null="true" />
        <property name="status" column="STATUS" type="java.lang.String" not-null="true" />
        <property name="createdOn" column="CREATED_ON" type="java.util.Date" not-null="true" />
        <property name="updatedOn" column="UPDATED_ON" type="java.util.Date" not-null="true" />
    
        <one-to-one name="user" class="Users" cascade="save-update" />
    </class> 

    and

    <class name="Users" table="USERS">
        <id name="username" column="USERNAME" type="java.lang.String">
            <generator class="assigned"/>
        </id>
        <property name="email" column="EMAIL" type="java.lang.String" not-null="true" />
        <property name="active" column="ACTIVE" type="java.lang.String" not-null="true" />
        <property name="createdOn" column="CREATED_ON" type="java.util.Date" not-null="true" />
        <property name="updatedOn" column="UPDATED_ON" type="java.util.Date" not-null="true" />
    
        <one-to-one name="registrations" class="Registrations" constrained="true" />
    </class>

    Try that out and let me know if it works now,

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: Hibernate one-to-one generation

You must be logged in to post in the forum log in