-->
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.  [ 3 posts ] 
Author Message
 Post subject: ManyToMany problems
PostPosted: Thu Sep 14, 2006 8:11 am 
Newbie

Joined: Thu Sep 14, 2006 7:29 am
Posts: 2
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

_________________
**
Jabbah.net (http://www.jabbah.net)
**


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 14, 2006 9:45 am 
Newbie

Joined: Thu Sep 14, 2006 7:29 am
Posts: 2
The problem with the "no session or session was closed " is solved by getting a Transaction through JNDI.

Though the ManyToMany problem persists....

_________________
**
Jabbah.net (http://www.jabbah.net)
**


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 5:04 pm 
Newbie

Joined: Sat Nov 19, 2005 1:01 pm
Posts: 9
<EDIT> Never mind. Posted to the wrong thread. My apologies.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.