2017-03-08 2 views
0

Pour objet persistant mappé avec table. La classe mappée doit être POJO avec toutes les règles de Plain Old Java Object. Son setter et getter ne devraient avoir aucun autre code d'initialisation de l'objet.Hibernate use plain POJO

public class Cat { 

      String id; 
      String name; 
      Type type; 


     /** 
     * @return the id 
     */ 
     public String getId() { 
      return id; 
     } 
     /** 
     * @param id the id to set 
     */ 
     public void setId(String id) { 
      if(id != null) { 
       type = new Type(); //This will cause in exception org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update 
            //ERROR 2017-03-07 00:37:30,253 [tomcat-http--22] - ERROR: cannot execute UPDATE in a read-only transaction 
      } 
      this.id = id; 
     } 
     /** 
     * @return the name 
     */ 
     public String getName() { 
      return name; 
     } 
     /** 
     * @param name the name to set 
     */ 
     public void setName(String name) { 
      this.name = name; 
     } 

Exception est: -

WARN 2017-03-07 00:37:30,253 [tomcat-http--22] - SQL Error: 0, SQLState: 25006 
ERROR 2017-03-07 00:37:30,253 [tomcat-http--22] - ERROR: cannot execute UPDATE in a read-only transaction 
ERROR 2017-03-07 00:37:30,254 [tomcat-http--22] - Could not synchronize database state with session 
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update 
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103) 
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91) 
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) 
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253) 
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266) 
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168) 
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) 
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) 
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) 

Pourquoi Mise en veille prolongée attendent que POJO avec des règles strictes? Est-ce que hibernate a des lignes directrices pour cela.

Cela fonctionne si je supprime le code de la méthode setId, seulement l'assignation de I'd.

+0

Cela montre comment Hibernate stupide et unflexible peut être parfois. (le message d'exception n'a tout simplement aucun sens) –

+0

Pourriez-vous fournir un échantillon de votre code? – Reborn

Répondre

1

On dirait que vous avez quelque part méthode marquée comme @Transactional (readonly = true)

+0

C'est une classe de pojo simple. Je n'utilise aucune annotation. Dans le fichier de mappage, rien n'est en lecture seule –