-->
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.  [ 9 posts ] 
Author Message
 Post subject: Entity and Table name Mapping
PostPosted: Mon Nov 21, 2005 1:46 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
Annotations: 3.1beta 6
Hibernate 3.1rc2
JDK 1.5.05
MYSQL 4.x

@Entity(access = AccessType.PROPERTY)
class Employee
{
@OneToMany
@JoinColumn(name="employeeOid")
public Set<EmployerEmployee> getEmployerEmployees();
}

@Entity(access = AccessType.PROPERTY)
@Table(name="EmployerEmployee"
class EmployerEmployee
{
@ManyToOne
@JoinColumn(name="employeeOid", insertable=false, updatable=false)
public Employee getEmployee()
}

So, what's the strange deal with the table name in the exception? Is that a bug?

java.sql.SQLException: Table 'MySchema.Employee_EmployerEmployees' doesn't exist
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:930)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1024)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:137)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1676)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1916)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1593)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:355)
at java.util.HashMap.hash(HashMap.java:264)
at java.util.HashMap.containsKey(HashMap.java:342)
at java.util.HashSet.contains(HashSet.java:182)
at org.apache.commons.lang.builder.ReflectionToStringBuilder.isRegistered(ReflectionToStringBuilder.java:141)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 1:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Is "Employee" the name of the schema?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 3:28 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
gavin wrote:
Is "Employee" the name of the schema?


Nope, schema name is MySchema.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 3:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Dunno then, one for Emmanuel.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 3:39 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
gavin wrote:
Dunno then, one for Emmanuel.



Error message actually says (note the lowercase e in _employerEmployees). My original message had a big E.

java.sql.SQLException: Table 'MySchema.Employee_employerEmployees' doesn't exist
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 3:46 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Please double check,
I'm 99% certain you have
hibernate.default_catalog=MySchema
hibernate.default_schema=Employee
in you config files

Other problem in a bidirectional relationship, one side has to be mappedBy

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 3:49 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ah forget the mappedBy, I didn't see your insert/update=false

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 4:03 am 
Regular
Regular

Joined: Thu Feb 17, 2005 1:58 am
Posts: 63
emmanuel wrote:
Please double check,
I'm 99% certain you have
hibernate.default_catalog=MySchema
hibernate.default_schema=Employee
in you config files

Other problem in a bidirectional relationship, one side has to be mappedBy


1% = I forgot to include the class EmployerEmployee in the hibernate config file :)

mappedBy is not needed because I used generic.

But I ran into what must be regular hibernate usage problem:

So first I used one session to query the object and at a later point used another session to delete. I think I can work this one out, but it is a bit surprising nevertheless.

org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:410)
at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:40)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:72)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:711)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:691)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 4:08 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ah interesting. In a short future, this error won't happen anymore, we'll enforce by annotation the idea of collection of elements.

For the second, this is a common user issue, you have to close the first session before working with the objects on another one

_________________
Emmanuel


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

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.