Code in java causes persistence problem

0

After adding the following lines to my class MetaDicas.java, a persistence problem appeared that there was not before:

Added lines:

@OneToMany(cascade=CascadeType.ALL)
@JoinColumn
private List<Integer> notas;

Error:

>javax.persistence.PersistenceException: [PersistenceUnit: h2PersistenceUnit] Unable to build EntityManagerFactory
 org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)
 org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899)
 org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:59)
 javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
 javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
 play.db.jpa.JPAPlugin.onStart(JPAPlugin.java:38)
 play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
 play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
 scala.collection.immutable.List.foreach(List.scala:383)
 play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:91)
 play.api.Play$$anonfun$start$1.apply(Play.scala:91)
 play.api.Play$$anonfun$start$1.apply(Play.scala:91)
 play.utils.Threads$.withContextClassLoader(Threads.scala:21)
 play.api.Play$.start(Play.scala:90)
 play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:157)
 play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:130)
 scala.Option.map(Option.scala:145)
 play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:130)
 play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:128)
 scala.util.Success.flatMap(Try.scala:230)
 play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:128)
 play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:120)
 scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
 scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
 scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1361)
 scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
 scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
 scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
 scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

I tried several ways but I could not fix it at all.

    
asked by anonymous 16.03.2015 / 17:24

2 answers

1

You must specify more the column you want to join. For example:

@OneToMany(fetch = FetchType.EAGER)
@JoinTable(name = "web_usuario_role", joinColumns = { @JoinColumn(name = "id_usuario", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "id_role", referencedColumnName = "id") })
private List<Papel> authorities;

I do not think it's possible to merge with a List of Integers.

    
16.03.2015 / 20:45
0

What the

  

ti.sof002

said is correct. However, be very careful with FetchType.EAGER and FetchType.Lazy. this may cause some compromodations for you. (slow system, "LazyInitializeException, Nullpointer" error, etc.)

When you need to bring a populated list, the list with a namedQuery is more popular.

/* Não é recomentado usar EAGER em mapeamentos OneToMany, pois quando este objeto for recuperado vai trazer a lista desse objeto e seus sub-objetos todos populados, issso pode deixar o sistema lento. Por padrão um mapeamento OneToMany já é Lazy, mas pode colocar para facilitar a leitura do código.*/
@OneToMany(fetch = FetchType.LAZY)     
@JoinTable(name = "web_usuario_role", joinColumns = { @JoinColumn(name = "id_usuario", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "id_role", referencedColumnName = "id") })
private List<Papel> authorities;

Hugs comments and critics are welcome: -)

    
24.03.2015 / 14:50