-->
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: Hibernate - SequenceGenerator and EmbeddedId
PostPosted: Thu Apr 28, 2016 4:54 pm 
Newbie

Joined: Thu Apr 28, 2016 4:49 pm
Posts: 2
Hello,

I am developing a system in an existing database and I have difficulty using a sequence of bank within a Hibernate Embeddable mapping.

Whenever I try to insert a new record value of idPessoa (PES_ID) is zero, it does not trigger the sequence.

Does anyone know how to solve this problem?

Class Main table:

Code:
@Entity 
@Table(name = "PES_PESSOA" ) 
public class Pessoa implements Serializable { 
 
private static final long serialVersionUID = 1L; 
 
@EmbeddedId   
private PessoaPK id; 
 
@Column(name = "PES_NOME" ) 
private String nome; 
 
@Column(name = "PES_LOGRADOURO" ) 
private String logradouro; 
 
@Column(name = "PES_BAIRRO" ) 
private String bairro;   
.... 



Class Embeddable with Sequence:

Code:
@Embeddable 
public class PessoaPK implements Serializable { 
 
private static final long serialVersionUID = 1L; 
 
@Column(name = "EMP_ID" ) 
private long idEmpresa; 
 
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenciaPessoa" ) 
@SequenceGenerator(name = "sequenciaPessoa", sequenceName = "S_PES_PESSOA", allocationSize = 1 ) 
@Column(name = "PES_ID" ) 
private long idPessoa; 
... 
}


Grateful!


Top
 Profile  
 
 Post subject: Re: Hibernate - SequenceGenerator and EmbeddedId
PostPosted: Thu May 05, 2016 3:57 pm 
Newbie

Joined: Thu Apr 28, 2016 4:49 pm
Posts: 2
Does anyone know if it is possible?

Thank you!


Top
 Profile  
 
 Post subject: Re: Hibernate - SequenceGenerator and EmbeddedId
PostPosted: Mon May 16, 2016 10:15 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I don't think that is possible to have @GeneratedValue with @EmbeddedId. However, you could use a regular EmbeedId and assign the value manually by calling a database sequence.


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.