-->
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: Newbie:Parent/child problem with MySql 5
PostPosted: Mon Sep 25, 2006 10:55 am 
Newbie

Joined: Fri Sep 22, 2006 6:19 am
Posts: 1
Well, i have hibernate 3.1 mysql 5 and tomcat 5.5

there is a problem in one-to-many relationships between Item and bid

Here is the code

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<property name="show_sql">true</property>
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="connection.url">jdbc:mysql://192.168.3.154:3306/prova</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.jdbc.batch_size">0</property>



<!-- Mapping files -->
<mapping resource="item-hbm.xml"/>
<mapping resource="bid-hbm.xml"/>
</session-factory>

</hibernate-configuration>

Bid

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="hibernate.Bid" table="BID">

<id name="id" column="BID_ID" unsaved-value="0">
<generator class="increment"/>
</id>



<property name="item_id"/>


<many-to-one name="item" column="ITEM_ID" class="hibernate.Item" not-null="true" />
<property name="amount"/>



</class>

</hibernate-mapping>

Item

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="hibernate.Item" table="ITEM">

<id name="id" column="ITEM_ID" unsaved-value="0">
<generator class="increment"/>
</id>


<set name="bids" inverse="true" cascade="save-update">
<key column="ITEM_ID"/>
<one-to-many class="hibernate.Bid"/>
</set>


<property name="name"/>

<property name="description"/>



</class>

</hibernate-mapping>

public class Bid {
private int id;
private int item_id;
private int amount;
private Item item;
/** Creates a new instance of Bid */
public Bid() {
}
public void setId(int idset){
this.id=idset;
}
public int getId(){
return id;
}
public void setItem_id(int item_id_set){
this.item_id=item_id_set;
}
public int getItem_id(){
return item_id;
}
public void setAmount(int amountset){
this.amount=amountset;
}
public int getAmount(){
return amount;
}
public void setItem(Item item) {
this.item=item;
}
public Item getItem(){
return item;
}
}


public class Bid {
private int id;
private int item_id;
private int amount;
private Item item;
/** Creates a new instance of Bid */
public Bid() {
}
public void setId(int idset){
this.id=idset;
}
public int getId(){
return id;
}
public void setItem_id(int item_id_set){
this.item_id=item_id_set;
}
public int getItem_id(){
return item_id;
}
public void setAmount(int amountset){
this.amount=amountset;
}
public int getAmount(){
return amount;
}
public void setItem(Item item) {
this.item=item;
}
public Item getItem(){
return item;
}
}


and the test code

Item prodotto = new Item();
Bid offerta = new Bid();
offerta.setAmount(100);

prodotto.setName("prodotto2");
prodotto.setDescription("il prodotto 2");

prodotto.addBid(offerta);
session.save(prodotto);
session.flush();


and the stack error

org.hibernate.exception.SQLGrammarException: could not insert: [hibernate.Bid]
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2078)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
hibernate.TestServlet.createItem(TestServlet.java:88)
hibernate.TestServlet.doGet(TestServlet.java:34)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 3:34 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
What's the real cause?

Turn on debuging log.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 11:02 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
please use the regular user forum, this question has nothing to do with EJB3

_________________
Emmanuel


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.