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.  [ 2 posts ] 
Author Message
 Post subject: mapping many-to-one
PostPosted: Tue Mar 28, 2006 8:49 am 
Newbie

Joined: Tue Mar 28, 2006 8:20 am
Posts: 1
Hibernate version: 3.1

Mapping documents:
-------------------------------------users.hbm.xml----------------------------------

<?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="test.datamodel.User" table="users">
<id name="id" type="integer" column="id">
<generator class="increment" />
</id>

<property name="firstName">
<column name="firstName" />
</property>
<property name="lastName">
<column name="lastName" />
</property>
<property name="login">
<column name="login " />
</property>
<property name="description">
<column name="description" />
</property>
<property name="password">
<column name="password"></column>
</property>
<set name="logs" cascade="all-delete-orphan">
<key column="user_ref_id" />
<one-to-many class="test.datamodel.Log" >
</set>
</class>
</hibernate-mapping>

-------------------------------------logs.hbm.xml----------------------------------

<?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="test.datamodel.Log" table="logs">
<id column="log_id" name="id" type="integer">
<generator class="increment" />
</id>
<property column="date" name="date" type="date"></property>
<property column="operation" name="operation" type="string"></property>
<property column="table" name="table" type="string"></property>
<property column="description" name="description"
type="string">
</property>
<property column="database" name="database" type="string"></property>
<many-to-one name="user_ref_id" column="user_ref_id" not-null="true"/>

</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():


Log log = new Log();
log.setDatabase("my_db");
log.setDate(new Date());
log.setDescription("this is a log description 1");
log.setOperation("Modify");
log.setTable("equipment");
User user = (User) session.load(User.class, new Integer(userId));
log.setUser_ref_id(user);
user.getLogs().add(aLog);
session.save(aLog);
session.flush();


Full stack trace of any exception that occurs:
Date : Tue Mar 28 14:31:43 CEST 2006
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
at test.dao.UserDAO.test(UserDAO.java:292)
at test.managers.UserManager.test(UserManager.java:164)
at test.managers.TestManagers.main(TestManagers.java:39)
Caused by: java.sql.BatchUpdateException: Erreur de syntaxe près de 'table, description, database, user_ref_id, log_id) values ('2006' à la ligne 1
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:896)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 8 more


org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
at test.dao.UserDAO.test(UserDAO.java:292)
at test.managers.UserManager.test(UserManager.java:164)
at test.managers.TestManagers.main(TestManagers.java:39)
Caused by: java.sql.BatchUpdateException: Erreur de syntaxe près de 'table, description, database, user_ref_id, log_id) values ('2006' à la ligne 1
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:896)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 8 more



Name and version of the database you are using: MySql 4.1.9

The generated SQL (show_sql=true):
Hibernate: select user0_.id as id0_0_, user0_.firstName as firstName0_0_, user0_.lastName as lastName0_0_, user0_.login as login4_0_0_, user0_.description as descript5_0_0_, user0_.password as password0_0_ from users user0_ where user0_.id=?
Hibernate: select logs0_.user_ref_id as user7_1_, logs0_.log_id as log1_1_, logs0_.log_id as log1_1_0_, logs0_.date as date1_0_, logs0_.operation as operation1_0_, logs0_.table as table1_0_, logs0_.description as descript5_1_0_, logs0_.database as database1_0_, logs0_.user_ref_id as user7_1_0_ from logs logs0_ where logs0_.user_ref_id=?
Hibernate: select max(log_id) from logs
Hibernate: insert into logs (date, operation, table, description, database, user_ref_id, log_id) values (?, ?, ?, ?, ?, ?, ?)


Debug level Hibernate log excerpt:info


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 4:32 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
j'imagine que table ou un des autres est un mot réservé de ta base de donnée

_________________
Emmanuel


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