-->
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: Cant insert/update an entity
PostPosted: Tue Jan 18, 2011 7:04 pm 
Newbie

Joined: Tue Jan 18, 2011 6:32 pm
Posts: 2
Hi people,
I`ve read the forums for a while but this is my first post so I wanted to greet the community.

I´m using last hibernate version, JPA and MySql 5.1.41 and the problem is as follows:

I have several business classes with their corresponding relationships and they work as they should except for one.

Hibernate its not even making the table for that entity. If I make it manually with the Workbench it still fails to insert or update that entity but I can retrieve the manually inserted data.

The exception is org.hibernate.exception.SQLGrammarException and the complete stack-trace:

Code:
org.hibernate.exception.SQLGrammarException: could not insert: [business.ParsingUnit]
Hibernate:
    insert
    into
        ParsingUnit
        (field,
    order, pattern, rssPattern_id)
values
    (?, ?, ?, ?)
   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:2327)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2834)
   at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:320)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)
   at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
   at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:799)
   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:791)
   at org.hibernate.engine.CascadingAction$8.cascade(CascadingAction.java:329)
   at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:392)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:335)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)
   at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:425)
   at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:362)
   at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:338)
   at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:204)
   at org.hibernate.engine.Cascade.cascade(Cascade.java:161)
   at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:475)
   at org.hibernate.event.def.DefaultPersistEventListener.entityIsPersistent(DefaultPersistEventListener.java:159)
   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)
   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
   at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808)
   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782)
   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786)
   at persistence.RssPatternDao.PersistRssPattern(RssPatternDao.java:53)
   at core.RssCaptureGui$3.actionPerformed(RssCaptureGui.java:613)
   at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
   at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
   at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
   at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
   at java.awt.Component.processMouseEvent(Unknown Source)
   at javax.swing.JComponent.processMouseEvent(Unknown Source)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Container.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Window.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'order, pattern, rssPattern_id) values ('Testing', 1, 'Testing', 10)' at line 1
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
   at com.mysql.jdbc.Util.getInstance(Util.java:384)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2409)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2327)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2312)
   at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
   at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
   ... 54 more
org.hibernate.AssertionFailure: null id in business.ParsingUnit entry (don't flush the Session after an exception occurs)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:82)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:147)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
   at persistence.RssPatternDao.PersistRssPattern(RssPatternDao.java:58)
   at core.RssCaptureGui$3.actionPerformed(RssCaptureGui.java:613)
   at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
   at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
   at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
   at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
   at java.awt.Component.processMouseEvent(Unknown Source)
   at javax.swing.JComponent.processMouseEvent(Unknown Source)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Container.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Window.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)


Class code:
Code:
package business;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

@Entity
public class ParsingUnit implements Serializable {

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private long id;

   private int order;

   private String pattern;

   private String field;

   @ManyToOne
   private RssPattern rssPattern;

......
"Getters and setters"
.......


And the code thats generating the error is:
Code:
..........................
ParsingUnit newParsingUnit = new ParsingUnit();

               try {
                  
                  newParsingUnit.setPattern(txtRegex.getText());
                  newParsingUnit.setField(txtObjectField.getText());
                  newParsingUnit.setOrder(Integer.parseInt(txtOrder.getText()));
                  newParsingUnit.setRssPattern(Core.getInstance().getPattern();
                  Core.getInstance().getPattern().getParsingUnits().add(newParsingUnit);
                  
                  
                  DaoFactory.getRssPatternDao().PersistRssPattern(Core.getInstance().getPattern());
............................


Dao code:
Code:
package persistence;

import java.util.List;

import org.hibernate.HibernateException;

import business.ParsingUnit;

public class ParsingUnitDao {

   private static ParsingUnitDao instance = new ParsingUnitDao();

   private ParsingUnitDao() {

   }

   public static ParsingUnitDao getInstance() {
      return instance;
   }

   public ParsingUnit getParsingUnitById(ParsingUnit obj) {
      .......
   }

   public List<ParsingUnit> getParsingUnits() {
      .......
   }

   public void PersistParsingUnit(ParsingUnit newParsingUnit) {
      HibernateUtil.getSession().beginTransaction();

      try {
         HibernateUtil.getSession().saveOrUpdate(newParsingUnit);
      } catch (HibernateException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } finally {
         HibernateUtil.getSession().getTransaction().commit();
      }

   }

}



The rest of the application is working just fine, even other entities with generated ids. I`ve tried all that came to my mind and searched the web but I´m still missing something... T_T

Thx in advance for any help whit this.


Top
 Profile  
 
 Post subject: Re: Cant insert/update an entity
PostPosted: Wed Jan 19, 2011 2:46 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
'order' is a reserved keyword in SQL so if you want to use if as a column name it needs to be quoted. See http://docs.jboss.org/hibernate/core/3. ... dentifiers for instructions how to enabled this.


Top
 Profile  
 
 Post subject: Re: Cant insert/update an entity
PostPosted: Wed Jan 19, 2011 12:05 pm 
Newbie

Joined: Tue Jan 18, 2011 6:32 pm
Posts: 2
..... if my db professor saw this..... I`ve dead.......

Thx nordborg.


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.