-->
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.  [ 14 posts ] 
Author Message
 Post subject: Mapping Cyclical References
PostPosted: Wed Jun 16, 2004 10:18 am 
Newbie

Joined: Tue Jun 08, 2004 8:07 pm
Posts: 14
Location: Washington, D.C.
Is it possible to map cyclical references using hibernate? This is currently my main road block for scrapping my home grown O/R mapping in favor of hibernate.

In particular my class looks like this....

public class KeyValuePair
{
private int id;
private int parentId;
private KeyValuePair[] categories = new KeyValuePair[ 0 ];

.....
}

I have a mapping file, but it fails to create the table for this class. Is this possible?

~harris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 10:20 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
yes it is possible you can have to-one and to-many relationship between the same class

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 10:33 am 
Newbie

Joined: Tue Jun 08, 2004 8:07 pm
Posts: 14
Location: Washington, D.C.
I have that in my map file....

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="KeyValuePair" table="taxonomyvalues">
<id name="id" type="integer" column="taxonomy_id" >
<generator class="hilo"/>
</id>
<property name="parentId" column="parentId" type="integer"/>
<property name="taxonomyKey" column="taxonomy_key" type="string"/>
<property name="key" column="key" type="string"/>
<property name="value" column="value" type="string"/>
<property name="enabled" column="enabled" type="boolean"/>
<array name="categories" table="taxonomyvalues" inverse="false" cascade="none">
<key column="taxonomy_id" foreign-key="taxonomy_key"/>
<index column="categories_index"/>
<one-to-many class="KeyValuePair"/>
</array>
</class>
</hibernate-mapping>


... but I get this when running Schema export....


create table taxonomyvalues (taxonomy_id INTEGER not null, parentId INTEGER, taxonomy_key VARCHAR(255), key VARCHAR(255), value VARCHAR(255), enabled BIT, categories_index INTEGER, primary key (taxonomy_id))
10:30:17,732 DEBUG SchemaExport:149 - create table taxonomyvalues (taxonomy_id INTEGER not null, parentId INTEGER, taxonomy_key VARCHAR(255), key VARCHAR(255), value VARCHAR(255), enabled BIT, categories_index INTEGER, primary key (taxonomy_id))
10:30:17,732 ERROR SchemaExport:154 - Unsuccessful: create table taxonomyvalues (taxonomy_id INTEGER not null, parentId INTEGER, taxonomy_key VARCHAR(255), key VARCHAR(255), value VARCHAR(255), enabled BIT, categories_index INTEGER, primary key (taxonomy_id))
10:30:17,732 ERROR SchemaExport:155 - Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR(255), value VARCHAR(255), enabled BIT, categories_index"


Gotta hate that! :-)

~harris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 10:36 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
it's just a schema creation problem not a hibernate problem, are you sure you are using the good dialect?

show hibernate.cfd.xml

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 10:44 am 
Newbie

Joined: Tue Jun 08, 2004 8:07 pm
Posts: 14
Location: Washington, D.C.
I'm not familiar with hibernate.cfd.xml [1]. Here is the config info from hibernate.properties....

# $Id: //kenobi/src/java/hibernate.properties#5 $
# $DateTime: 2004/04/20 13:00:57 $
# $Revision: #5 $

hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
#hibernate.dialect net.sf.hibernate.dialect.OracleDialect
#hibernate.dialect com.dante.util.OptimizeOracleDialect

hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://localhost/test

....

hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'
hibernate.query.imports net.sf.hibernate.test, net.sf.hibernate.eg
hibernate.use_outer_join false
hibernate.jdbc.use_scrollable_resultset false
hibernate.jdbc.use_streams_for_binary true
hibernate.show_sql false

## set the maximum JDBC 2 batch size (a nonzero value enables batching)
hibernate.jdbc.batch_size 0

thanks,

~harris

[1] http://www.google.com/search?hl=en&ie=U ... gle+Search


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 10:48 am 
Newbie

Joined: Tue Jun 08, 2004 8:07 pm
Posts: 14
Location: Washington, D.C.
Maybe I could get similiar behavior by using a TreeMap for the hierarchical data instead of a cyclical reference. Does hibernate support mapping a tree structure?

thanks a bunch for the tips,

~harris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 10:53 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you're going to change your structure just because schema export throw an error?
do what you want

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 10:57 am 
Newbie

Joined: Tue Jun 08, 2004 8:07 pm
Posts: 14
Location: Washington, D.C.
I'd rather not change the structure, but I need to do whatever works. Is there a dialect for MySQL that I am missing that would help with the SchemaExport?

~harris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 10:59 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
let's wait for an expert of schema export or mySQL.... be patient

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 11:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
"key" is a keyword on mysql. Rename the column in the mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 11:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
mickeal = mySql ShemaExport Hero !

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 11:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Did I mention already that I hate mysql :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 11:09 am 
Newbie

Joined: Tue Jun 08, 2004 8:07 pm
Posts: 14
Location: Washington, D.C.
michael & anthony = my hibernate heros;

thanks,

~harris


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 11:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i've done nothing... just advised you to be patient ;)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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