I have 2 entities, the SubModel that has a list of possible options. I made a unidirectional OneToMany relation, when I do any persistence in the SubModel entity that the list of Options is empty Hibernate does quietly, but without having to include / edit the relationship of it with the Options therein the error occurs. The way I did this relationship is wrong?
@Entity
public class SubModelo implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@Column
@Size(max=30)
private String nome;
@NotNull
@Size (max=1)
private String portas;
@NotNull
@Size (max=9)
private String motor;
@NotNull
@Enumerated
private Combustivel comb;
@NotNull
private boolean automatico;
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinTable(name="SUBMODELO_TEM_OPCS", joinColumns={@JoinColumn(name="SUBMODELO_ID", referencedColumnName="id")}, inverseJoinColumns={@JoinColumn(name="OPCIONAL_ID", referencedColumnName="id")})
private List<Opcional> opc;
The Optional entity:
@Entity public class Optional implements Serializable { private static final long serialVersionUID = 3L;
Id @GeneratedValue (strategy = GenerationType.AUTO) private Integer id; @Column @Size (max = 35) @NotNull (message="Optional Name Must Be Reported!") private String name; @Column @Size (max = 150) @NotNull (message="Detailed Description Should Be Reported!") private String description; @Column (length = 1) @NotNull private String level; @Column (length = 3) private String icon;
The error:
23:55:03,875 ERROR [org.jboss.as.ejb3.invocation] (default task-2) WFLYEJB0034: EJB Invocation failed on component SubModeloService for method public br.com.ozelo.entidades.SubModelo br.com.ozelo.servico.SubModeloService.novoSubModelo(br.com.ozelo.entidades.SubModelo): javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.Integer br.com.ozelo.entidades.Opcional.id] by reflection for persistent property [br.com.ozelo.entidades.Opcional#id] : ABS at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:187) at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:277) at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:327) at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:47) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:100) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) at org.jboss.as.ejb3.deployment.processors.StartupAwaitInterceptor.processInvocation(StartupAwaitInterceptor.java:22) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: javax.persistence.PersistenceException: org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.Integer br.com.ozelo.entidades.Opcional.id] by reflection for persistent property [br.com.ozelo.entidades.Opcional#id] : ABS at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1608) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275) ... 103 more