- This topic has 6 replies, 3 voices, and was last updated 19 years, 10 months ago by support-jeff.
-
AuthorPosts
-
girikrishvaMemberI 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.
Riyad KallaMemberCan you post the schema for the tables and the generated hbm.xml files?
girikrishvaMemberUSERS
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 nullREGISTRATIONS
username varchar2(240) not null – PK
email varchar2(240) not null
statusvarchar2(240) not null
created_on date not null
updated_on date not nullFK relationship
USERS.username (FK) to REGISTRATIONS.usernamehibernate.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”><!– 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” ><!– 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” ><!– 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>
Riyad KallaMemberHave 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?
girikrishvaMemberYes
girikrishvaMemberAny progress please?
support-jeffMemberYou 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,
-
AuthorPosts