-->
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.  [ 1 post ] 
Author Message
 Post subject: Saving OneToMany , foreign key not set Postgres
PostPosted: Tue Jul 02, 2013 10:42 am 
Newbie

Joined: Tue Jul 02, 2013 10:37 am
Posts: 1
I'm usign Spring + JPA + Hibernate + postgres, my problem is with cascade, I'm trying to save a "Criterio" adding a "Justificativa", and then save the criterio by cascading, but the Foreign Key is not setted

"Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "id" violates not-null constraint
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)"

Code:
@Entity
   public class Criterio extends PersistableImpl {

   private static final long serialVersionUID = 1L;

   @Id   
    @GeneratedValue(strategy = GenerationType.IDENTITY)   
   @Column(name="id", unique=true, nullable=false)
   Integer id;
   
   @Column
   private String name;

   @OneToMany(mappedBy="criterio", cascade= {javax.persistence.CascadeType.ALL} )
   private List<Justificativa> justificativas;
   .....GETTERS AND SETTERS


Code:
   @Entity
   public class Justificativa extends PersistableImpl {

   private static final long serialVersionUID = -1374632123186791897L;

@Id   
    @GeneratedValue(strategy = GenerationType.IDENTITY)   
   @Column(name="id", unique=true, nullable=false)
   Integer id;
   
   @Column(name="description")
   private String description;
   
   @ManyToOne()
    @JoinColumn(name="criterio_id", nullable=false, insertable=true, updatable=true)
    private Criterio criterio;
    ....GETTERS AND SETTERS


/////////

Code:
Justificativa just = new Justificativa();
   just.setDescription("test");
   criterio.getJustificativas().add(just);
   criterio = service.save(criterio);

////////
The service.save calls the following method
Code:
@Override
   @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
   public T saveOrUpdate(T t) {
      this.em.clear();
      this.em.merge(t);
      return t;
   }


Someone can help me? I've no Idea what is the problem, I tried some solutions, but no one worked for me.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.