0
votes

I can't seem to figure out what is wrong.
While using plays framework CRUD module to insert information into DB (mySql)
(I am using the default module insertion mechanism as shown at http://www.playframework.org/documentation/1.0.1/crud)
I receive the following exception

PersistenceException occured : org.hibernate.exception.GenericJDBCException: could not insert: [models.Mail]

In {module:crud}/app/controllers/CRUD.java (around line 152)

             } catch (TemplateNotFoundException e) {
                 render("CRUD/blank.html", type, object);
             }

          } 

  Here -> object._save(); 
          flash.success(play.i18n.Messages.get("crud.created", type.modelName)); 
         if (params.get("_save") != null) { 
             redirect(request.controller + ".list"); 
          } 
          if (params.get("_saveAndAddAnother") != null) { 

         redirect(req

uest.controller + ".blank");

here is my mail entity class:

@Entity
public class Mail extends Model {


   public String title;

   public Date sentAt;
   @OneToMany
   public Set<User> sentTO;
   @OneToMany
   public Set<User> sentBCC;


    public String content;

    @ManyToOne
    public User author;

    public Mail(User author, ... ){

      //more code here
    }

}

controller

package controllers;

/**
 *
 * @author mike
 */
public class Mails extends CRUD{

}

[full stack]

Execution exception (In {module:crud}/app/controllers/CRUD.java around line 152) PersistenceException occured : org.hibernate.exception.GenericJDBCException: could not insert: [models.Mail]

play.exceptions.JavaExecutionException: org.hibernate.exception.GenericJDBCException: could not insert: [models.Mail] at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231) at Invocation.HTTP Request(Play!) Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not insert: [models.Mail] at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153) at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:678) at play.db.jpa.JPABase._save(JPABase.java:25) at controllers.CRUD.create(CRUD.java:152) at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548) at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502) at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478) at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473) at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161) ... 1 more Caused by: org.hibernate.exception.GenericJDBCException: could not insert: [models.Mail] at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) 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:2345) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2852) 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.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69) at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135) 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 org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:672) ... 8 more Caused by: java.sql.SQLException: Field 'isAdmin' doesn't have a default value at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2111) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2407) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2325) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2310) at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57) ... 23 more

any ideas?

2
Have you extended your Controller with CRUD controller given by Playbasav
can you copy the whole stacktrace of the error?Romain Linsolas
added controller and full stack, as you can see it extends CRUD class.james

2 Answers

4
votes

See the actual cause

Caused by: java.sql.SQLException: Field 'isAdmin' doesn't have a default value

Looks like you're trying to save into a row without setting the isAdmin property (which is also not defined in your model, but might be in your actual database?).

1
votes

Well looking into your POJO class that you have not stetted you Admin property so

Hibernate can not find the admin root where it can add the values. example is follows.

 @javax.persistence.Entity
    @Table(name = "Spring_Login")
    public class Table_Login implements Serializable {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "id")
        private int id;
}

and then sql Syntax wont be fail and that then sql query will be the same and your Error will be solved.