Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Complex Hibernate mapping (or not?)

Reply
Thread Tools

Complex Hibernate mapping (or not?)

 
 
Snyke
Guest
Posts: n/a
 
      05-21-2006
Hehe, your wish is my command ^^
I think it's best if I put all relevant parts online to show you ^^:

First of all the classes I want to persist:
- http://snyke.net/tmp/UserAccount.java
- http://snyke.net/tmp/FinancialAccount.java
Then the part that initializes Hibernate:
- http://snyke.net/tmp/HibernateSessionFactory.java
And then the hibernate config & mapping files:
- http://snyke.net/tmp/hibernate.cfg.xml
- http://snyke.net/tmp/mapping.hbm.xml

This way we don't get messy posts and I hope you have all information
^^

Thanks for all your help until now
Snyke

 
Reply With Quote
 
 
 
 
Danno
Guest
Posts: n/a
 
      05-21-2006
And Privilege.java?

 
Reply With Quote
 
 
 
 
Snyke
Guest
Posts: n/a
 
      05-22-2006
Ok, as so often I forgot the most important thing ^^

http://snyke.net/tmp/Privilege.java

 
Reply With Quote
 
JScoobyCed
Guest
Posts: n/a
 
      05-22-2006
Snyke wrote:
> Once again I'm running against a solid wall of errors, and my head
> starts to hurt really badly with this one
> I have a bidirectional link between two classes
>
> Account <=> User
>
> this being a many-to-many relationship. Until now nothing fancy, but I
> have a Class inbetween that manages accessrights called Privilge, this
> just has two boolean values (read and write) that tell wether a user
> can read or write to the account.
>
> Account <-many-to-one-> Privilege <-one-to-many-> User
>
> basically every Account-User combination has a Privilege.


Hi. I followed this Thread and triied to give it a check.
I downloaded your code and ran it. I need to create a class BaseVO.java
as you didn't provide it. Here is what I put:

<BaseVO.java>
public class BaseVO {
private int id = -1;
private Privilege[] userPrivileges = null;

public int getId() {
return id;
}

public void setId(int i) {
id = i;
}

public Privilege[] getUserPrivileges() {
return userPrivileges;
}

public void setUserPrivileges(Privilege[] priv) {
userPrivileges = priv;
}
}
</BaseVO.java>

I am not sure the set/get on userPrivileges are in this class or not.
But Hibernate was complaining there was no setter/getter for
userPrivileges in UserAccount. I thought ot put it in BaseVo as it was
not in your original UserAccount.java

Anyway, after creating the DB in mysql, the only output I have is:

classic factory

I don't have any error message. So I guess you might have a different DB
than me. Here is my DB script:

<db_mysql>
CREATE TABLE accounts (
id int(11) NOT NULL,
`name` varchar(32) NOT NULL
);

CREATE TABLE privilege (
id int(11) NOT NULL auto_increment,
isread tinyint(4) NOT NULL,
iswrite tinyint(4) NOT NULL,
`user` int(11) NOT NULL,
account int(11) NOT NULL,
PRIMARY KEY (id)
);

CREATE TABLE users (
id int(11) NOT NULL auto_increment,
`name` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
user_privileges int(11) NOT NULL,
PRIMARY KEY (id)
);

</db_mysql>

Note that MySQl (and many DBMS) have 'user', 'password' and 'name'
reserved (so MySQl encloses them with backquotes). Maybe that's what is
perturbing Hibernate. I am using hibernate 3.

--
JSC
 
Reply With Quote
 
Snyke
Guest
Posts: n/a
 
      05-23-2006
Finally!

I got Hibernate to work correctly, but I really can't tell what I
changed. After being very close to giving up on hibernate (yes, I
nearly coded all persistence directly into the objects...) I decided,
that I'd give it a last try, with a completely new Project and going
step by step through it, and it worked just perfect.

Here's a link to this sample application, hope it may help others ^^
http://www.snyke.net/tmp/HibernateTest.tar.bz2

Thanks for all contributors,
Christian 'Snyke' Decker
http://www.Snyke.net

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hibernate LazyInitializationException in web application Struts asMVC, Spring as IOC and Hibernate as ORM layer Amit Jain Java 7 04-27-2009 10:27 AM
HIBERNATE - java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration Eleanna Skouta Java 2 12-09-2008 02:09 AM
Hibernate cannot find hibernate.cfg.xml jstorta Java 1 01-19-2008 01:45 PM
Hibernate Syncronizer now generates code for Hibernate 3.0 msenin@covad.net Java 0 07-14-2005 05:47 AM
[HIBERNATE] [EVALUATION] - Gavin King Censors Hibernate Forum Ilias Lazaridis Java 0 12-27-2004 04:26 AM



Advertisments