Problem when a relationship persists

Asked

Viewed 214 times

1

I have 2 entities, the Submodel has a list of possible Options.

I made a unidirectional Onetomany relation, when I make any persistence in the entity Submodel that the list of Options this empty the Hibernate does quietly, but without having to include/edit her relationship with the Optionals then occurs the error.

The way I made this relationship this 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;
}
@Entity
public class Opcional implements Serializable {
    private static final long serialVersionUID = 3L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @Column
    @Size(max = 35)
    @NotNull(message = "Nome do Opcional Deve Ser Informado!")
    private String nome;

    @Column
    @Size(max = 150)
    @NotNull(message = "Descrição Detalhada Deve Ser Informado!")
    private String descricao;

    @Column(length = 1)
    @NotNull
    private String nivel;

    @Column(length = 3)
    private String icon;
}

The mistake:

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
  • 1

    post the other side of the relationship, in case the class Optional.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.