Hi,
I've been getting problems using @Valid (pointed in code) in deep.
These are my entity relationships:
1 Cep (PostalCode) -> 1 UnidadeFederativa (State)
1 Cep (PostalCode) -> 1 Cidade (City)
1 Cep (PostalCode) -> 1 Bairro (Neighbourhood)
1 UnidadeFederativa (State) -> N Cidades (Cities)
1 Cidade (City) -> N Bairros (Neighbourhoods)
Think my problem has a lot of the same symptons listed here:
http://opensource.atlassian.com/project ... rowse/HV-7
Thanks.
Code:
@Entity
@Table(name = "CEP")
public class Cep implements Serializable {
@Id @GeneratedValue
private Long id;
@NotNull
private String cep;
@NotNull
private String siglaPais;
//@Valid //Causing exception when uncommented
@OneToOne
@JoinColumn(name="idUnidadeFederativa")
private UnidadeFederativa unidadeFederativa = new UnidadeFederativa();
@Valid
@OneToOne
@JoinColumn(name="idCidade")
private Cidade cidade = new Cidade();
@Valid
@OneToOne
@JoinColumn(name="idBairro")
private Bairro bairro = new Bairro();
Code:
@Entity
@Table(name = "UNIDADE_FEDERATIVA")
public class UnidadeFederativa implements Serializable, Comparable<UnidadeFederativa> {
@Id @GeneratedValue
private Long id;
private String siglaPais;
@NotNull
@Length(max=50)
private String nome;
private String sigla;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="idCapital")
private Cidade capital;
@Valid
@OneToMany(cascade = CascadeType.ALL)
@MapKey(name="nome")
@JoinColumn(name="idUnidadeFederativa")
@Sort(type = SortType.NATURAL)
private Map<String, Cidade> cidades = new TreeMap<String,Cidade>();
Code:
@Entity
@Table(name = "CIDADE")
public class Cidade implements Serializable {
@Id @GeneratedValue
private Long id;
@NotNull
@Length(max=100)
private String nome;
//@Valid //Causing exception when uncommented
@OneToMany(cascade = CascadeType.ALL)
@MapKey(name="nome")
@JoinColumn(name="idCidade")
@Sort(type = SortType.NATURAL)
private Map<String, Bairro> bairros = new TreeMap<String, Bairro>();
Code:
@Entity
@Table(name = "BAIRRO")
public class Bairro implements Serializable {
@Id @GeneratedValue
private Long id;
@NotNull
@Length(max=50)
private String nome;
public Bairro() {
}
public Bairro(long id, String nome) {
this.id = id;
this.nome = nome;
}
EntityManager Log
Code:
15:59:25,593 INFO Version:15 - Hibernate EntityManager 3.2.1.GA
15:59:25,625 INFO Version:15 - Hibernate Annotations 3.2.1.GA
15:59:25,640 INFO Environment:514 - Hibernate 3.2.4.sp1
15:59:25,656 INFO Environment:547 - hibernate.properties not found
15:59:25,656 INFO Environment:681 - Bytecode provider name : cglib
15:59:25,656 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
Junit Error
Code:
com.buscape.CepTest Time elapsed: 1,188,327,566.89 sec <<< ERROR!
java.lang.Exception: javax.persistence.PersistenceException: java.lang.NullPointerException
at com.buscape.CepTest.inicializa(CepTest.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:42)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:135)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:160)
at org.apache.maven.surefire.Surefire.run(Surefire.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:241)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:812)
Caused by: javax.persistence.PersistenceException: java.lang.NullPointerException
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:252)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at com.buscape.CepTest.inicializa(CepTest.java:80)
... 18 more
Caused by: java.lang.NullPointerException
at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:142)
at org.hibernate.validator.ClassValidator.createChildValidator(ClassValidator.java:252)
at org.hibernate.validator.ClassValidator.initValidator(ClassValidator.java:224)
at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:149)
at org.hibernate.validator.ClassValidator.createChildValidator(ClassValidator.java:252)
at org.hibernate.validator.ClassValidator.initValidator(ClassValidator.java:224)
at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:134)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:318)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:183)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:240)
... 22 more