-->
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: ClassCastException from ForeignGenerator
PostPosted: Thu Jan 19, 2006 4:00 am 
Newbie

Joined: Thu Jan 19, 2006 3:40 am
Posts: 8
Hi All,

This is a question concerning a mapping file.

The Object World: Two Classes A and B, where B is a mapping between three instances of A.

class B {
A a1;
A a2;
A a3;
}

I don't want a surrogate key, but one of the mapped instances (say a1 ist the primary key)

The DB table is:

A (id, ...)
B (primary foreign key a1, foreign key a2, foreign key a3)

At the moment my mapping looks like:

<hibernate-mapping>
<class name="..B" schema="C" table="B">
<id name="a1" column="A1">
<generator class="foreign">
<param name="property">a1</param>
</generator>
</id>
<one-to-one name="a1" />
<many-to-one column="A2" name="a2" not-null="true"/>
<many-to-one column="A3" name="a3" not-null="true"/>
</class>
</hibernate-mapping>


I am far from sure that this is correct but it is the best idea I have at the moment.

When I try to insert an instance of B in the DB I get the following exception:

java.lang.ClassCastException
at org.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:50)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:544)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:533)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:529)
at com.temp.FillDB.fillDB(FillDB.java:429)
at com.temp.FillDB.main(FillDB.java:218)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)


What is my mistake?

Thanks a lot,

Philipp

_________________
Philipp Seuring


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.