-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Mapping Exception for a simple example. help needed
PostPosted: Mon Oct 15, 2007 3:54 pm 
Newbie

Joined: Mon Oct 15, 2007 3:35 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I am trying to get a simple Account, Roles, AcountRoleMap example
to work.

The generated schema for postgresql is fine.
The generated pojos look fine.

But I can't get the test code to compile. It bombs on initialization of the HibernateUtil class.

I've tried lots of things, but ether the generated ddl gets messed up or the pojos aren't what I expect. I have tried using one-to-many (see exception trace).

thanks


Hibernate version: 3.2.5

Mapping documents:

<hibernate-mapping
package="com.mikeh.orm.generated.om"
schema="public" >

<class name="Account"
table="account"
dynamic-update="true"
dynamic-insert="true" >

<id name="id" type="integer">
<meta attribute="use-in-tostring">true</meta>
<column name="id" sql-type="int4" default="nextval('public.account_id_seq'::text)" />
<generator class="sequence">
<param name="sequence">account_id_seq</param>
</generator>
</id>

<property name="email" type="java.lang.String" >
<column name="email" length="80" not-null="true" unique="true" />
</property>

<!-- an Account has a set of roles -->
<set name = "roleSet" table="accountrolemap" inverse="true" cascade="all-delete-orphan">
<key
on-delete="cascade"
foreign-key="fk_ac_to_account" >
<column name ="accountid" not-null="true" sql-type="int4" />
</key>
<many-to-many column="accountid" class="Account" foreign-key="tmp"/>
</set>

</class>


<class name="Role"
table="role"
dynamic-update="false"
dynamic-insert="false"
>

<id name="id" type="integer">
<meta attribute="use-in-tostring">true</meta>
<column name="id" sql-type="int4" default="nextval('public.role_id_seq'::text)" />
<generator class="sequence">
<param name="sequence">role_id_seq</param>
</generator>
</id>

<property name="name" type="java.lang.String" >
<meta attribute="use-in-tostring">true</meta>
<column name="name" length="20" unique="true"/>
</property>

<!-- a role can be associated with a set of accounts -->
<set name = "accountSet" table="accountrolemap" inverse="true" cascade="all-delete-orphan">
<key
on-delete="cascade"
foreign-key="fk_ac_to_role" >
<column name ="roleid" not-null="true" sql-type="int4" />
</key>
<many-to-many column="roleid" class="Role"/>
</set>

</class>
<class name="AccountRoleMap" table="accountrolemap"
dynamic-update="false"
dynamic-insert="false"
schema="public" >
<id name="id" type="integer">
<meta attribute="use-in-tostring">true</meta>
<column name="id" sql-type="int4" default="nextval('public.accountrolemap_id_seq'::text)" />
<generator class="sequence">
<param name="sequence">accountrolemap_id_seq</param>
</generator>
</id>


<property name="roleId" type="java.lang.Integer" >
<column name ="roleid" not-null="true" sql-type="int4" />
</property>
<property name="accountId" type="java.lang.Integer" >
<column name ="accountid" not-null="true" sql-type="int4" />
</property>


<!-- If you want getRoleId(), getAccountId() -->
<!--
<property name="roleId" type="java.lang.Integer" >
<column name ="roleid" not-null="true" sql-type="int4" />
</property>

<property name="accountId" type="java.lang.Integer" >
<column name ="accountid" not-null="true" sql-type="int4" />
</property>
-->

</class>


</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
NA
Full stack trace of any exception that occurs:
Initial SessionFactory creation failed.org.hibernate.MappingException: only inverse one-to-many associations may use on-delete="cascade": com.mikeh.orm.generated.om.Account.roleSet
[java] Exception in thread "main" java.lang.ExceptionInInitializerError
[java] at com.mikeh.orm.HibernateUtil.<clinit>(HibernateUtil.java:17)

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.