Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » (no subject)
(no subject) [message #724836] Tue, 13 September 2011 06:08 Go to next message
nocknock  is currently offline nocknock
Messages: 12
Registered: June 2011
Junior Member
Hello friends.

I'm trying to run a native sentence to get records, but I get an error, which refers to primary keys are null when no records with null key in my table ("Alergia").

Code to execute sentence:getEntityManager().createNativeQuery("SELECT a FROM Alergia a", com.os.ud.entities.Alergia.class).getResultList()

Entity:@Entity
@Table(name = "alergia")
@XmlRootElement
@NamedQueries({@NamedQuery(name = "Alergia.findAll", query = "SELECT a FROM Alergia a"),
@NamedQuery(name = "Alergia.findByCodigo", query =
"SELECT a FROM Alergia a WHERE a.codigo = :codigo"),
@NamedQuery(name = "Alergia.findByNombre", query =
"SELECT a FROM Alergia a WHERE a.nombre = :nombre"),
@NamedQuery(name = "Alergia.findByDescripcion", query =
"SELECT a FROM Alergia a WHERE a.descripcion = :descripcion")})
public class Alergia implements Serializable {

private static final long serialVersionUID = 1L;
@TableGenerator(name = "Ale_Gen", table = "id_gen", pkColumnName = "gen_name",
valueColumnName = "gen_val", allocationSize=1)
@Id @GeneratedValue(generator="Ale_Gen")
@Basic(optional = false)
@NotNull
@Column(name = "codigo")
private Integer codigo;
@Size(max = 50)
@Column(name = "nombre")
private String nombre;
@Size(max = 200)
@Column(name = "descripcion")
private String descripcion;
@ManyToMany(mappedBy = "alergiaList")
private List<Paciente> pacienteList;
//


public Alergia() {
}


public Alergia(Integer codigo) {
this.codigo = codigo;
}


public Integer getCodigo() {
return codigo;
}


public void setCodigo(Integer codigo) {
this.codigo = codigo;
}

....


Error:
Exception occurred in target VM:
Exception Description: The primary key read from the row [ArrayRecord(
=> (2,"Acido Salicilico",jfasif))] during the execution of the query was detected to be null. Primary keys must not contain null.
Query: ReadAllQuery(referenceClass=Alergia sql="SELECT a FROM Alergia a")
org.eclipse.persistence.exceptions.QueryException:
Exception Description: The primary key read from the row [ArrayRecord(
=> (2,"Acido Salicilico",jfasif))] during the execution of the query was detected to be null. Primary keys must not contain null.
Query: ReadAllQuery(referenceClass=Alergia sql="SELECT a FROM Alergia a")
at org.eclipse.persistence.exceptions.QueryException.nullPrimaryKeyInBuildingObject(QueryException.java:885)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:592)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:568)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:733)
at org.eclipse.persistence.queries.ReadAllQuery.registerResultInUnitOfWork(ReadAllQuery.java:767)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:431)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1097)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:829)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1056)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:390)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1144)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2863)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1501)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1483)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1457)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:485)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:742)
at com.os.ud.facades.AbstractFacade.findListByNativeQuery(AbstractFacade.java:500)
at com.os.ud.facades.AbstractFacade.findListByNativeQuery(AbstractFacade.java:473)
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:597)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5366)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:46)
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:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
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:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5338)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5326)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at $Proxy403.findListByNativeQuery(Unknown Source)
at com.os.ud.facades.__EJB31_Generated__ProcFacade__Intf____Bean__.findListByNativeQuery(Unknown Source)
at com.os.ud.jsf.classes.util.sqlmodel.MySqlLDM.load(MySqlLDM.java:80)
at org.primefaces.component.datatable.DataTable.loadLazyData(DataTable.java:692)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:568)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:227)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:205)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:95)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
<

However, the following code works well, and should get the same records as the code above.
getEntityManager().createNamedQuery("Alergia.findAll", com.os.ud.entities.Alergia.class).getResultList()


Can you help me?

Thank You, very much


Version:
EclipseLink 2.2.0
Netbeans 7.0.1.
GlassFish 3.1.
Ubuntu 11.04
Re: (no subject) [message #724874 is a reply to message #724836] Tue, 13 September 2011 08:01 Go to previous message
nocknock  is currently offline nocknock
Messages: 12
Registered: June 2011
Junior Member
I screwed up.
I'm so sorry.
I hope you haven't wasted your time.

I had to be used "createQuery" instead of "createNativeQuery."

Thank you.
(no subject) [message #724875 is a reply to message #724836] Tue, 13 September 2011 08:00 Go to previous message
nocknock  is currently offline nocknock
Messages: 12
Registered: June 2011
Junior Member
I screwed up.
I'm so sorry.
I hope you haven't wasted your time.

I had to be used "createQuery" instead of "createNativeQuery."

Thank you.
(no subject) [message #724876 is a reply to message #724836] Tue, 13 September 2011 08:01 Go to previous message
nocknock  is currently offline nocknock
Messages: 12
Registered: June 2011
Junior Member
I screwed up.
I'm so sorry.
I hope you haven't wasted your time.

I had to be used "createQuery" instead of "createNativeQuery."

Thank you.
Previous Topic:Error Null primary key, but it's not null
Next Topic:Eclipse link and db description in xml
Goto Forum:
  


Current Time: Thu Aug 21 02:33:38 EDT 2014

Powered by FUDForum. Page generated in 0.01634 seconds