Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » null exception when using find
null exception when using find [message #1814840] Fri, 20 September 2019 02:25
Jon Morgan is currently offline Jon MorganFriend
Messages: 6
Registered: October 2015
Junior Member
Hi Folks,

I'm new to JPA and Eclipselink (2.7).

I'm getting null exception when using em.find, even when em.contains returns true.

I use a composite key @Embeddable class MenuCategoryPK for entity MenuCategory.
It seems to be a problem in CMP3Policy.createPrimaryKeyFromId - see attached screen shot.


Here the test code.


@Stateless
@Named("MenuCategoryEJB")
public class MenuCategoryEJB implements Serializable {

private static final long serialVersionUID = 1876760979130925618L;

@PersistenceContext(unitName = "ordersys")
private EntityManager em;
private static Logger logger = Logger.getLogger("ordersys");


/**
* Default constructor.
*/
public MenuCategoryEJB() {
// TODO Auto-generated constructor stub

}

public void testJPA(ActionEvent actionEvent) {

MenuCategory targetMC=null;
logger.info(this.getClass() + " : testJPA : start");

List<MenuCategory> mcList= getListFirstLevelMenuCategoriesByMenuId("000001");
logger.info(this.getClass() + " : testJPA : mcList.size=" + mcList.size());

MenuCategory mcItem=mcList.get(1);
try {
logger.info(this.getClass() + " : testJPA : em.isOpen=" + em.isOpen());

logger.info(this.getClass() + " : testJPA : mcItem.getId().getMenuId()=" + mcItem.getId().getMenuId());
logger.info(this.getClass() + " : testJPA : mcItem.getId().getmenucategoryId()=" + mcItem.getId().getmenucategoryId());

logger.info(this.getClass() + " : testJPA : PRE MERGE em.contains(mctest)=" + em.contains(mcItem));
em.merge(mcItem);
logger.info(this.getClass() + " : testJPA : POST MERGE em.contains(mctest)=" + em.contains(mcItem));

targetMC = em.find(MenuCategory.class, mcItem.getId());

logger.info(this.getClass() + " : testJPA : targetMC.getId().getMenuId()=" + targetMC.getId().getMenuId());
logger.info(this.getClass() + " : testJPA : targetMC.getId().getmenucategoryId()=" + targetMC.getId().getmenucategoryId());

} catch(Exception ex) {
logger.info(this.getClass() + " : testJPA : ex=" + ex.getMessage());
}

logger.info(this.getClass() + " : testJPA : finish");
}

}


this is the run result

11:54:29,830 INFO [ordersys] (default task-1) class ejb.MenuCategoryEJB : testJPA : start
11:54:29,836 INFO [ordersys] (default task-1) class ejb.MenuCategoryEJB : testJPA : mcList.size=27
11:54:32,315 INFO [ordersys] (default task-1) class ejb.MenuCategoryEJB : testJPA : em.isOpen=true
11:54:34,020 INFO [ordersys] (default task-1) class ejb.MenuCategoryEJB : testJPA : mcItem.getId().getMenuId()=000001
11:54:34,020 INFO [ordersys] (default task-1) class ejb.MenuCategoryEJB : testJPA : mcItem.getId().getmenucategoryId()=4
11:54:34,020 INFO [ordersys] (default task-1) class ejb.MenuCategoryEJB : testJPA : PRE MERGE em.contains(mctest)=true
11:54:34,020 INFO [ordersys] (default task-1) class ejb.MenuCategoryEJB : testJPA : POST MERGE em.contains(mctest)=true
11:56:24,149 INFO [ordersys] (default task-1) class ejb.MenuCategoryEJB : testJPA : ex=null
11:56:24,149 INFO [ordersys] (default task-1) class ejb.MenuCategoryEJB : testJPA : finish





Stack dump

Thread [default task-1] (Suspended (breakpoint at line 230 in CMP3Policy))
CMP3Policy.createPrimaryKeyFromId(Object, AbstractSession) line: 230
EntityManagerImpl.findInternal(ClassDescriptor, AbstractSession, Object, LockModeType, Map<String,Object>) line: 900
EntityManagerImpl.find(Class<T>, Object, LockModeType, Map<String,Object>) line: 822
EntityManagerImpl.find(Class<T>, Object) line: 688
TransactionScopedEntityManager(AbstractEntityManager).find(Class<T>, Object) line: 213
MenuCategoryEJB.testJPA(ActionEvent) line: 455
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 62
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
Method.invoke(Object, Object...) line: 567
ManagedReferenceMethodInterceptor.processInvocation(InterceptorContext) line: 52
InterceptorContext.proceed() line: 422
InterceptorContext$Invocation.proceed() line: 509
Jsr299BindingsInterceptor.delegateInterception(InvocationContext, InterceptionType, List<Interceptor<?>>, InterceptorInstances) line: 79
Jsr299BindingsInterceptor.doMethodInterception(InvocationContext, InterceptionType, InterceptorInstances, InterceptorBindings) line: 89
Jsr299BindingsInterceptor.processInvocation(InterceptorContext) line: 102
UserInterceptorFactory$1.processInvocation(InterceptorContext) line: 63
InterceptorContext.proceed() line: 422
ExecutionTimeInterceptor.processInvocation(InterceptorContext) line: 43
InterceptorContext.proceed() line: 422
SBInvocationInterceptor.processInvocation(InterceptorContext) line: 47
InterceptorContext.proceed() line: 422
ConcurrentContextInterceptor.processInvocation(InterceptorContext) line: 45
InterceptorContext.proceed() line: 422
InitialInterceptor.processInvocation(InterceptorContext) line: 40
InterceptorContext.proceed() line: 422
ChainedInterceptor.processInvocation(InterceptorContext) line: 53
ComponentDispatcherInterceptor.processInvocation(InterceptorContext) line: 52
InterceptorContext.proceed() line: 422
PooledInstanceInterceptor.processInvocation(InterceptorContext) line: 51
InterceptorContext.proceed() line: 422
AdditionalSetupInterceptor.processInvocation(InterceptorContext) line: 54
InterceptorContext.proceed() line: 422
CMTTxInterceptor.invokeInOurTx(InterceptorContext, EJBComponent) line: 237
CMTTxInterceptor.required(InterceptorContext, EJBComponent, int) line: 362
CMTTxInterceptor.processInvocation(InterceptorContext) line: 144
InterceptorContext.proceed() line: 422
InterceptorContext$Invocation.proceed() line: 509
EjbRequestScopeActivationInterceptor(AbstractEJBRequestScopeActivationInterceptor).aroundInvoke(InvocationContext) line: 72
EjbRequestScopeActivationInterceptor.processInvocation(InterceptorContext) line: 89
InterceptorContext.proceed() line: 422
CurrentInvocationContextInterceptor.processInvocation(InterceptorContext) line: 41
InterceptorContext.proceed() line: 422
WaitTimeInterceptor.processInvocation(InterceptorContext) line: 47
InterceptorContext.proceed() line: 422
SecurityContextInterceptor.processInvocation(InterceptorContext) line: 100
InterceptorContext.proceed() line: 422
StartupAwaitInterceptor.processInvocation(InterceptorContext) line: 22
InterceptorContext.proceed() line: 422
ShutDownInterceptorFactory$1.processInvocation(InterceptorContext) line: 64
InterceptorContext.proceed() line: 422
LoggingInterceptor.processInvocation(InterceptorContext) line: 67
InterceptorContext.proceed() line: 422
NamespaceContextInterceptor.processInvocation(InterceptorContext) line: 50
InterceptorContext.proceed() line: 422
ContextClassLoaderInterceptor.processInvocation(InterceptorContext) line: 60
InterceptorContext.proceed() line: 422
InterceptorContext.run() line: 438
WildFlySecurityManager.doChecked(PrivilegedExceptionAction<T>) line: 618
AccessCheckingInterceptor.processInvocation(InterceptorContext) line: 57
InterceptorContext.proceed() line: 422
ChainedInterceptor.processInvocation(InterceptorContext) line: 53
ViewService$View.invoke(InterceptorContext) line: 198
ViewDescription$1.processInvocation(InterceptorContext) line: 185
ProxyInvocationHandler.invoke(Object, Method, Object[]) line: 81
MenuCategoryEJB$$$view16.testJPA(ActionEvent) line: not available
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 62
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
Method.invoke(Object, Object...) line: 567
Reflections.invokeAndUnwrap(Object, Method, Object...) line: 410
EnterpriseBeanProxyMethodHandler<T>.invoke(Object, Method, Method, Object[]) line: 134
InjectionPointPropagatingEnterpriseTargetBeanInstance(EnterpriseTargetBeanInstance).invoke(Object, Method, Object...) line: 56
InjectionPointPropagatingEnterpriseTargetBeanInstance.invoke(Object, Method, Object...) line: 68
ProxyMethodHandler.invoke(Object, Method, Method, Object[]) line: 106
MenuCategoryEJB$Proxy$_$$_Weld$EnterpriseProxy$.testJPA(ActionEvent) line: not available
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 62
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
Method.invoke(Object, Object...) line: 567
ReflectionUtil.invokeMethod(ELContext, Method, Object, Object[]) line: 157
AstValue.invoke(EvaluationContext, Class[], Object[]) line: 265
MethodExpressionImpl.invoke(ELContext, Object[]) line: 280
WeldMethodExpression(ForwardingMethodExpression).invoke(ELContext, Object[]) line: 40
WeldMethodExpression.invoke(ELContext, Object[]) line: 50
WeldMethodExpression(ForwardingMethodExpression).invoke(ELContext, Object[]) line: 40
WeldMethodExpression.invoke(ELContext, Object[]) line: 50
TagMethodExpression.invoke(ELContext, Object[]) line: 65
MethodExpressionActionListener.processAction(ActionEvent) line: 124
ActionEvent.processListener(FacesListener) line: 72
CommandButton(UIComponentBase).broadcast(FacesEvent) line: 490
CommandButton(UICommand).broadcast(FacesEvent) line: 211
UIViewRoot.broadcastEvents(FacesContext, PhaseId) line: 847
UIViewRoot.processApplication(FacesContext) line: 1395
InvokeApplicationPhase.execute(FacesContext) line: 58
InvokeApplicationPhase(Phase).doPhase(FacesContext, Lifecycle, ListIterator<PhaseListener>) line: 76
LifecycleImpl.execute(FacesContext) line: 177
FacesServlet.executeLifecyle(FacesContext) line: 707
FacesServlet.service(ServletRequest, ServletResponse) line: 451
ServletHandler.handleRequest(HttpServerExchange) line: 74
FilterHandler$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 129
SpanFinishingFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 55
ManagedFilter.doFilter(ServletRequest, ServletResponse, FilterChain) line: 61
FilterHandler$FilterChainImpl.doFilter(ServletRequest, ServletResponse) line: 131
FilterHandler.handleRequest(HttpServerExchange) line: 84
ServletSecurityRoleHandler.handleRequest(HttpServerExchange) line: 62
ServletChain$1.handleRequest(HttpServerExchange) line: 68
ServletDispatchingHandler.handleRequest(HttpServerExchange) line: 36
SecurityContextAssociationHandler.handleRequest(HttpServerExchange) line: 78
PredicateHandler.handleRequest(HttpServerExchange) line: 43
SSLInformationAssociationHandler.handleRequest(HttpServerExchange) line: 132
ServletAuthenticationCallHandler.handleRequest(HttpServerExchange) line: 57
PredicateHandler.handleRequest(HttpServerExchange) line: 43
ServletConfidentialityConstraintHandler(AbstractConfidentialityHandler).handleRequest(HttpServerExchange) line: 46
ServletConfidentialityConstraintHandler.handleRequest(HttpServerExchange) line: 64
AuthenticationMechanismsHandler.handleRequest(HttpServerExchange) line: 60
CachedAuthenticatedSessionHandler.handleRequest(HttpServerExchange) line: 77
NotificationReceiverHandler.handleRequest(HttpServerExchange) line: 50
SecurityInitialHandler(AbstractSecurityContextAssociationHandler).handleRequest(HttpServerExchange) line: 43
PredicateHandler.handleRequest(HttpServerExchange) line: 43
JACCContextIdHandler.handleRequest(HttpServerExchange) line: 61
PredicateHandler.handleRequest(HttpServerExchange) line: 43
GlobalRequestControllerHandler.handleRequest(HttpServerExchange) line: 68
PredicateHandler.handleRequest(HttpServerExchange) line: 43
ServletInitialHandler.handleFirstRequest(HttpServerExchange, ServletRequestContext) line: 292
ServletInitialHandler.access$100(ServletInitialHandler, HttpServerExchange, ServletRequestContext) line: 81
ServletInitialHandler$2.call(HttpServerExchange, ServletRequestContext) line: 138
ServletInitialHandler$2.call(HttpServerExchange, Object) line: 135
ServletRequestContextThreadSetupAction$1.call(HttpServerExchange, C) line: 48
ContextClassLoaderSetupAction$1.call(HttpServerExchange, C) line: 43
SecurityContextThreadSetupAction.lambda$create$0(ThreadSetupHandler$Action, HttpServerExchange, Object) line: 105
980673153.call(HttpServerExchange, Object) line: not available
UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(ThreadSetupHandler$Action, HttpServerExchange, Object) line: 1502
820757914.call(HttpServerExchange, Object) line: not available
UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(ThreadSetupHandler$Action, HttpServerExchange, Object) line: 1502
820757914.call(HttpServerExchange, Object) line: not available
UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(ThreadSetupHandler$Action, HttpServerExchange, Object) line: 1502
820757914.call(HttpServerExchange, Object) line: not available
UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(ThreadSetupHandler$Action, HttpServerExchange, Object) line: 1502
820757914.call(HttpServerExchange, Object) line: not available
UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(ThreadSetupHandler$Action, HttpServerExchange, Object) line: 1502
820757914.call(HttpServerExchange, Object) line: not available
ServletInitialHandler.dispatchRequest(HttpServerExchange, ServletRequestContext, ServletChain, DispatcherType) line: 272
ServletInitialHandler.access$000(ServletInitialHandler, HttpServerExchange, ServletRequestContext, ServletChain, DispatcherType) line: 81
ServletInitialHandler$1.handleRequest(HttpServerExchange) line: 104
Connectors.executeRootHandler(HttpHandler, HttpServerExchange) line: 364
HttpServerExchange$1.run() line: 830
ContextClassLoaderSavingRunnable.run() line: 35
EnhancedQueueExecutor.safeRun(Runnable) line: 1982
EnhancedQueueExecutor$ThreadBody.doRunTask(Runnable) line: 1486
EnhancedQueueExecutor$ThreadBody.run() line: 1377
Thread.run() line: 835



@Embeddable
public class MenuCategoryPK implements Serializable {

private static final long serialVersionUID = 18739723L;

@Column(name="menu_id", insertable=false, updatable=false)
private String menuId;

@Column(name="menucategory_id", insertable=false, updatable=true) // JM
private String menucategoryId;

public MenuCategoryPK() {
}
public String getMenuId() {
return this.menuId;
}
public void setMenuId(String menuId) {
this.menuId = menuId;
}
public String getmenucategoryId() {
return this.menucategoryId;
}
public void setmenucategoryId(String categoryId) {
this.menucategoryId = categoryId;
}

public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof MenuCategoryPK)) {
return false;
}
MenuCategoryPK castOther = (MenuCategoryPK)other;
return
this.menuId.equals(castOther.menuId)
&& this.menucategoryId.equals(castOther.menucategoryId);
}

public int hashCode() {
final int prime = 31;
int hash = 17;
hash = hash * prime + this.menuId.hashCode();
hash = hash * prime + this.menucategoryId.hashCode();

return hash;
}
}

@Entity
@Table(name="menucategories")
@NamedQuery(name="MenuCategory.findAll", query="SELECT m FROM MenuCategory m")
public class MenuCategory implements Serializable {
private static final long serialVersionUID = 1L;

@EmbeddedId
private MenuCategoryPK id;


private Integer seqno;

@Column(name="parent_menucategory_id", insertable=true, updatable=true)
private String parent_menucategory_id;

@ManyToOne
@JoinColumn(name="menu_id")
private Menu menus;

@OneToOne
@PrimaryKeyJoinColumn(name="category_id", referencedColumnName="id")
private Category category;

@OneToOne
@JoinColumns({
@JoinColumn(name="MENU_ID", referencedColumnName="menu_id", insertable=false, updatable=false),
@JoinColumn(name="CATEGORY_ID", referencedColumnName="category_id", insertable=false, updatable=false)
})
private MenuCategory parent_menu_category;

@OneToMany(mappedBy="parent_menu_category")
private List<MenuCategory> menusubcategories = new ArrayList<MenuCategory>();

public List<MenuCategory> getMenusubcategories() {
return menusubcategories;
}

public void setMenusubcategories(List<MenuCategory> menusubcategories) {
this.menusubcategories = menusubcategories;
}

@OneToMany(mappedBy="menucategory")
private List<MenuCategoryProduct> menucategoryproducts;

public MenuCategory() {
}

public Category getCategory() {
return this.category;
}


public MenuCategoryPK getId() {
return this.id;
}

public void setId(MenuCategoryPK id) {
this.id = id;
}

public Integer getSeqno() {
return this.seqno;
}

public void setSeqno(Integer seqno) {
this.seqno = seqno;
}

public Menu getMenus() {
return this.menus;
}

public void setMenus(Menu menus) {
this.menus = menus;
}


public List<MenuCategoryProduct> getMenuCategoryProducts() {
return this.menucategoryproducts;
}

public void setMenucategoryproducts(List<MenuCategoryProduct> menucategoryproducts) {
this.menucategoryproducts = menucategoryproducts;
}

public MenuCategoryProduct addMenucategoryproduct(MenuCategoryProduct menucategoryproduct) {
getMenuCategoryProducts().add(menucategoryproduct);
menucategoryproduct.setMenucategory(this);

return menucategoryproduct;
}

public MenuCategoryProduct removeMenucategoryproduct(MenuCategoryProduct menucategoryproduct) {
getMenuCategoryProducts().remove(menucategoryproduct);
menucategoryproduct.setMenucategory(null);

return menucategoryproduct;
}

/**
* @return the parent_category_id
*/
public String getParent_category_id() {
return parent_menucategory_id;
}

/**
* @param parent_category_id the parent_category_id to set
*/
public void setParent_category_id(String parent_category_id) {
this.parent_menucategory_id = parent_category_id;
}

/**
* @return the parent_menu_category
*/
public MenuCategory getParent_menu_category() {
return parent_menu_category;
}

/**
* @param parent_menu_category the parent_menu_category to set
*/
public void setParent_menu_category(MenuCategory parent_menu_category) {
this.parent_menu_category = parent_menu_category;
}


}
Previous Topic:@ManyToMany: Why columns order in primary key depends on entity class names?
Next Topic:eclipselink 2.7.4 and java 13 causes java.lang.IllegalArgumentException
Goto Forum:
  


Current Time: Fri Apr 19 16:17:23 GMT 2024

Powered by FUDForum. Page generated in 0.01858 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top