• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one to many mapping(unidirection)

 
hemantha kumark
Greenhorn
Posts: 1
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2329)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2836)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344)
at $Proxy8.save(Unknown Source)
at com.hibernate.Test.main(Test.java:52)
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'name' in 'field list'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
... 22 more







 
Waswani Naresh
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?

Regards,
Naresh Waswani
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Raj,

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

Regards,
Naresh Waswani
 
in Mkumar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

-Manoj

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic