aspose file tools
The moose likes Object Relational Mapping and the fly likes one to many mapping(unidirection) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "one to many mapping(unidirection)" Watch "one to many mapping(unidirection)" New topic

one to many mapping(unidirection)

hemantha kumark

Joined: Jun 05, 2011
Posts: 1

i am not getting where i made mistake, can any one help me out.
i am getting org.hibernate.exception.SQLGrammarException: could not insert:

Parent class

Child class

Test class to run the project

this is what i'm getting output

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
alter table Child drop foreign key FK3E104FCC4758C38
drop table if exists Child
drop table if exists Parent
create table Child (childId integer not null auto_increment, name varchar(255), children_parentId integer, primary key (childId))
create table Parent (parentId integer not null auto_increment, name varchar(255), primary key (parentId))
alter table Child add index FK3E104FCC4758C38 (children_parentId), add constraint FK3E104FCC4758C38 foreign key (children_parentId) references Parent (parentId)
Hibernate: insert into Child (name) values (?)
Hibernate: insert into Child (name) values (?)
Hibernate: insert into Parent (name) values (?)
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [com.hibernate.Parent]
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.persister.entity.AbstractEntityPersister.insert(
at org.hibernate.persister.entity.AbstractEntityPersister.insert(
at org.hibernate.action.EntityIdentityInsertAction.execute(
at org.hibernate.engine.ActionQueue.execute(
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(
at org.hibernate.event.def.AbstractSaveEventListener.performSave(
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(
at org.hibernate.impl.SessionImpl.fireSave(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(
at $ Source)
at com.hibernate.Test.main(
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'name' in 'field list'
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.MysqlIO.checkErrorPacket(
at com.mysql.jdbc.MysqlIO.sendCommand(
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(
at com.mysql.jdbc.Connection.execSQL(
at com.mysql.jdbc.PreparedStatement.executeInternal(
at com.mysql.jdbc.PreparedStatement.executeUpdate(
at com.mysql.jdbc.PreparedStatement.executeUpdate(
at com.mysql.jdbc.PreparedStatement.executeUpdate(
... 22 more

Waswani Naresh
Ranch Hand

Joined: May 01, 2008
Posts: 66
Hi Hemantha,

I tried executing your code and surprisingly I did not get any error. Could you please furnish what version of hibernate and mysql you are using ?

Naresh Waswani

Naresh Waswani
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 445

The below line in the StackTrace should be the cause.

Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'name' in 'field list'

Waswani Naresh
Ranch Hand

Joined: May 01, 2008
Posts: 66

The error could be MySQL/Hibernate version specific. I did not get this error on MySQL 5.2 and Hibernate 3.5.1.

Naresh Waswani
in Mkumar

Joined: Sep 08, 2008
Posts: 20
Hey ,

Seems problem with "name" field.

hence the below error you are getting -

Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'name' in 'field list'

Please verify whether field is available in the corresponding table in the database and also ensure the naming.


I agree. Here's the link:
subject: one to many mapping(unidirection)