Glassfish version:
V1 b48
Hibernate version:
hibernate core: 3.2 cr2
hibernate annotations: 3.2.0 cr1
hibernate entity manager: 3.2.0 cr1
Full stack trace of any exception that occurs:
[#|2006-09-14T13:22:28.353+0200|INFO|sun-appserver-pe9.0|javax.enterprise.system.stream.out|_ThreadID=10;_ThreadName=main;|2006-09-1
4 13:22:28,353 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <Unsuccessful: create table UserGroup_User (groups_groupId integer
not null, members_userId integer not null, key integer, primary key (groups_groupId, key))>
[#|2006-09-14T13:22:28.353+0200|INFO|sun-appserver-pe9.0|javax.enterprise.system.stream.out|_ThreadID=10;_ThreadName=main;|2006-09-1
4 13:22:28,353 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <You have an error in your SQL syntax. Check the manual that corre
sponds to your MySQL server version for the right syntax to use near 'integer, primary key (groups_groupId, key))' at line 1>
|#]
Name and version of the database you are using:
MySQL 4.0.24
Hello everyone,
I have just started using Hibernate in Glassfish. The reason for abandoning Toplink Ess. is that it has no clustered cache as of yet.
After some twiddling I got most of my classes working, but there is two problems that I haven't been able to fix yet.
The first is about a ManyToMany relation that creates a join table.
The 2 classes are:
Code:
class User{
@Id
public int getUserId() {
return userId;
}
....
@ManyToMany(mappedBy="members")
@JoinColumn(name="groupId")
public Map<Integer,UserGroup> getGroups(){
return groups;
}
...
}
class UserGroup{
@Id
public int getGroupId() {
return groupId;
}
....
@ManyToMany
@JoinColumn(name="userId")
public Map<Integer,User> getMembers() {
return members;
}
....
}
The problem is, as can be seen from the log that the SQL to create the join table wants to create a field called 'key' of type integer. First of all, I don't know why it wants that key field, second it should use the name 'key' for the field because this is not allowed in MySQL.
What can I do to resolve this problem. I was unable to find a similar post about this.
---------------------------
The second problem is about a OneToMany relation that seems to do lazy collection fetching. I must be honest that I still need to research this a bit further, but I don't understand why it doesn't work.
The code:
Code:
class Forum{
@Id
public int getForumId(){
return forumId;
}
....
@OneToMany
public Collection<UserGroup> getSecurityGroups(){
return securityGroups;
}
....
}
When I try to access a member of the securityGroups I get the following:
Code:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: net.jabbah.core.Forum.securityGroups, no session or session was closed
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:246)
This all used to work with Toplink Essentials JPA
My main concern is for the first question.
Thanks a lot in advance