JPA - Many To One relationship not working - jpa

I m having a problem with JPA ManyToOne relationship. I have two entities (HikeList, User):
#Entity
#Table(name = "T_HIKELIST")
public class Hikelist implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.TABLE)
private long id;
#Size(min = 1, max = 50)
#ManyToOne(optional = false)
#JoinColumn(name = "login", referencedColumnName = "login")
private User user;
...
}
And
#Entity
#Table(name = "T_USER")
public class User implements Serializable {
#NotNull
#Size(min = 0, max = 50)
#Id
private String login;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
private Collection<Hikelist> hikeListCollection;
...
}
My test class :
...
#Test
public void testCreateUser() {
User user = new User();
user.setLogin("thomaslogin");
user.setEmail("thomas#gmail.com");
user.setPassword("thomas");
user.setFirstName("thomas");
user.setLastName("thomas");
userService.createUser(user);
Hikelist hike = new Hikelist();
hike.setId(new Long(1L));
hike.setLabel("GR20");
hike.setUser(user);
hikeService.createHikeList(hike);
Hikelist hike1 = hikeRepository.findOne(new Long(1L));
assertNotNull(hike1);
}
I m getting the following error when I m calling : hikeService.createHikeList(hike);
Does anybody know where I am wrong?
Thank you in advance.
org.springframework.transaction.TransactionSystemException: Could not
commit JPA transaction; nested exception is
javax.persistence.RollbackException: Error while committing the
transaction at
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:524)
at
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
at
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
at
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478)
at
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)
at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
at
com.breizh.packlight.service.HikelistService$$EnhancerBySpringCGLIB$$38379214.createHikeList()
at
com.breizh.packlight.service.HikelistServiceTest.testCreateUser(HikelistServiceTest.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.persistence.RollbackException: Error while committing
the transaction at
org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:94)
at
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:515)
... 37 more Caused by: javax.validation.UnexpectedTypeException:
HV000030: No validator could be found for type:
com.breizh.packlight.domain.User. at
org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.verifyResolveWasUnique(ConstraintValidatorManager.java:218)
at
org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.findMatchingValidatorClass(ConstraintValidatorManager.java:193)
at
org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.getInitializedValidator(ConstraintValidatorManager.java:97)
at
org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:125)
at
org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:91)
at
org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:85)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:478)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:424)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:388)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:340)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:158)
at
org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:137)
at
org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:95)
at
org.hibernate.action.internal.EntityInsertAction.preInsert(EntityInsertAction.java:206)
at
org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:96)
at
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:453)
at
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:345)
at
org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
at
org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1218)
at
org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:421)
at
org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at
org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
at
org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:77)
... 38 more

The error is:
javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: com.breizh.packlight.domain.User
And it's caused by
#Size(min = 1, max = 50)
private User user;
How can a User have a size between 1 and 50?
Validation constraints apply the the Java objects. Not to the columns in the database. You already make sure that the login is of the right size, and the user field is mapped to a column which has a foreign key constraint, so the #Size annotation here is not only not working, but unnecessary.

Related

EclipseLink -Prevent inserting to child entity in onetoMany releation at particular case

Am struggling for almost a day trying to prevent saving to child entity(USER) it will have value already so dont perform insert/update on user from company.
Reference Links
How to avoid insert and update queries in one-to-many uni-directional association
How to prevent saving child object with JPA?
JPA: Prevent cascade parent from saving
Actual code:
Company:
#OneToMany(mappedBy = "parentCompany")
private List<User> users;
User:
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "ID_COMPANIES")
private Company parentCompany;
Tried one by one
#OneToMany(mappedBy = "parentCompany", cascade = CascadeType.PERSIST)
#JoinColumn(name = "ID_USERS", insertable = false, updatable = false)
private List<User> users;
#OneToMany(mappedBy = "parentCompany")
#JoinColumn(name = "ID_USERS", insertable = false, updatable = false)
private List<User> users;
#OneToMany(mappedBy = "parentCompany", fetch = FetchType.LAZY)
private List<User> users;
// called getuser().size to initialize
#OneToMany(mappedBy = "parentCompany", fetch = FetchType.EAGER)
private List<User> users;
// called getuser().size to initialize and its returning vector but insert not preventing.
Saving:
public T update(T t) {
return this.entityManager.merge(t);
}
Error:
Caused by:
java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: com.volvocars.tis.domain.model.User#4.
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.discoverUnregisteredNewObjects(RepeatableWriteUnitOfWork.java:313)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:727)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:441)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:878)
at org.eclipse.persistence.internal.jpa.QueryImpl.performPreQueryFlush(QueryImpl.java:967)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeUpdate(QueryImpl.java:296)
at com.volvocars.tis.domain.dao.bean.CompanyAddressDaoBean.updateVolvoAddress(CompanyAddressDaoBean.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:508)
at com.ibm.ejs.container.EJSContainer.invokeProceed(EJSContainer.java:4886)
at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:592)
at com.ibm.ws.cdi.ejb.impl.InterceptorChain.proceed(InterceptorChain.java:119)
at com.ibm.ws.cdi.ejb.impl.EJBCDIInterceptorWrapper.invokeInterceptors(EJBCDIInterceptorWrapper.java:131)
at com.ibm.ws.cdi.ejb.impl.EJBCDIInterceptorWrapper.aroundInvoke(EJBCDIInterceptorWrapper.java:54)
at sun.reflect.GeneratedMethodAccessor59.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:508)
at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:189)
at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:577)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64)
at com.ibm.ws.cdi.ejb.interceptor.WeldSessionBeanInterceptorWrapper.aroundInvoke(WeldSessionBeanInterceptorWrapper.java:58)
at sun.reflect.GeneratedMethodAccessor58.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:508)
at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:189)
How to prevent saving child entity on particular case? Any way can achieve programmatically or with annoation?

java.lang.IllegalArgumentException: The attribute [state_id] is not present in the managed type [EntityTypeImpl#530144602:Cities]

I'm new in javaEE. recently I'm working on restful Web Services using jax-rs and using JPA for working with databases and using Netbeans as an IDE and TomeEE as Web Server.
about my problem,
I have a table that was called cities which have 3 column :
id, state_id, name
(state_id is defined as foreign key to another column is called states)
I want to select all cities which have a certain state_id, for example in the table, 1000 rows exist that their state_id are 8.
this is my JPA code:
public List<T> findByStateID(Short id){
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery(entityClass);
javax.persistence.criteria.Root<T> r = cq.from(entityClass);
cq.select(r);
cq.where(getEntityManager().getCriteriaBuilder().equal(r.get("state_id"), id));
return getEntityManager().createQuery(cq).getResultList();
}
and this is the Web Service code:
#GET
#Path("State/{id}")
#Produces(MediaType.APPLICATION_JSON)
public List<Cities> findByState(#PathParam("id") Short id){
return super.findByStateID(id);
}
know my problem is that when I access to the target url I get blow error:
HTTP Status 500 - Error processing webservice request
type Exception report
message Error processing webservice request
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Error processing webservice request
org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:98)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
java.lang.IllegalArgumentException: The attribute [state_id] is not present in the managed type [EntityTypeImpl#530144602:Cities [ javaType: class entity.Cities descriptor: RelationalDescriptor(entity.Cities --> [DatabaseTable(cities)]), mappings: 4]].
org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl.getAttribute(ManagedTypeImpl.java:148)
org.eclipse.persistence.internal.jpa.querydef.FromImpl.get(FromImpl.java:312)
rest.AbstractFacade.findByStateID(AbstractFacade.java:50)
rest.CitiesFacadeREST.findByState(CitiesFacadeREST.java:49)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:205)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:186)
org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)
org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:205)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:186)
org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:236)
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:203)
org.apache.openejb.util.proxy.ProxyEJB$Handler.invoke(ProxyEJB.java:74)
rest.CitiesFacadeREST$$LocalBeanProxy.findByState(rest/CitiesFacadeREST.java)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.openejb.server.cxf.rs.OpenEJBEJBInvoker.performInvocation(OpenEJBEJBInvoker.java:95)
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:189)
org.apache.openejb.server.cxf.rs.OpenEJBEJBInvoker.invoke(OpenEJBEJBInvoker.java:68)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99)
org.apache.openejb.server.cxf.rs.AutoJAXRSInvoker.invoke(AutoJAXRSInvoker.java:64)
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:254)
org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:251)
org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
note The full stack trace of the root cause is available in the Apache Tomcat (TomEE)/8.5.3 (7.0.1) logs.
Apache Tomcat (TomEE)/8.5.3 (7.0.1)
here is the Cities entity class:
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* #author seyed
*/
#Entity
#Table(name = "cities")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Cities.findAll", query = "SELECT c FROM Cities c"),
#NamedQuery(name = "Cities.findById", query = "SELECT c FROM Cities c WHERE c.id = :id"),
#NamedQuery(name = "Cities.findByName", query = "SELECT c FROM Cities c WHERE c.name = :name")})
public class Cities implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Basic(optional = false)
#Column(name = "id")
private Short id;
#Basic(optional = false)
#NotNull
#Size(min = 1, max = 65)
#Column(name = "name")
private String name;
#JoinColumn(name = "state_id", referencedColumnName = "id")
#ManyToOne(optional = false)
private States stateId;
#OneToMany(cascade = CascadeType.ALL, mappedBy = "city")
private Collection<Users> usersCollection;
public Cities() {
}
public Cities(Short id) {
this.id = id;
}
public Cities(Short id, String name) {
this.id = id;
this.name = name;
}
public Short getId() {
return id;
}
public void setId(Short id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public States getStateId() {
return stateId;
}
public void setStateId(States stateId) {
this.stateId = stateId;
}
#XmlTransient
public Collection<Users> getUsersCollection() {
return usersCollection;
}
public void setUsersCollection(Collection<Users> usersCollection) {
this.usersCollection = usersCollection;
}
#Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Cities)) {
return false;
}
Cities other = (Cities) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
#Override
public String toString() {
return "entity.Cities[ id=" + id + " ]";
}
}
as said in comments , I changed state_id to stateId in jpa part and now I get this error:
HTTP Status 500 - Error processing webservice request
type Exception report
message Error processing webservice request
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Error processing webservice request
org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:98)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
javax.persistence.PersistenceException: Exception [EclipseLink-6078] (Eclipse Persistence Services - 2.6.3.v20160428-59c81c5): org.eclipse.persistence.exceptions.QueryException
Exception Description: The class of the argument for the object comparison is incorrect.
Expression: [
Base entity.Cities]
Mapping: [org.eclipse.persistence.mappings.ManyToOneMapping[stateId]]
Argument: [1]
Query: ReadAllQuery(referenceClass=Cities )
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:484)
rest.AbstractFacade.findByStateID(AbstractFacade.java:51)
rest.CitiesFacadeREST.findByState(CitiesFacadeREST.java:49)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:205)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:186)
org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)
org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:205)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:186)
org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:236)
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:203)
org.apache.openejb.util.proxy.ProxyEJB$Handler.invoke(ProxyEJB.java:74)
rest.CitiesFacadeREST$$LocalBeanProxy.findByState(rest/CitiesFacadeREST.java)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.openejb.server.cxf.rs.OpenEJBEJBInvoker.performInvocation(OpenEJBEJBInvoker.java:95)
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:189)
org.apache.openejb.server.cxf.rs.OpenEJBEJBInvoker.invoke(OpenEJBEJBInvoker.java:68)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99)
org.apache.openejb.server.cxf.rs.AutoJAXRSInvoker.invoke(AutoJAXRSInvoker.java:64)
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:254)
org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:251)
org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
Exception [EclipseLink-6078] (Eclipse Persistence Services - 2.6.3.v20160428-59c81c5): org.eclipse.persistence.exceptions.QueryException
Exception Description: The class of the argument for the object comparison is incorrect.
Expression: [
Base entity.Cities]
Mapping: [org.eclipse.persistence.mappings.ManyToOneMapping[stateId]]
Argument: [1]
Query: ReadAllQuery(referenceClass=Cities )
org.eclipse.persistence.exceptions.QueryException.incorrectClassForObjectComparison(QueryException.java:601)
org.eclipse.persistence.mappings.OneToOneMapping.buildObjectJoinExpression(OneToOneMapping.java:298)
org.eclipse.persistence.internal.expressions.RelationExpression.normalize(RelationExpression.java:830)
org.eclipse.persistence.internal.expressions.SQLSelectStatement.normalize(SQLSelectStatement.java:1474)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.buildNormalSelectStatement(ExpressionQueryMechanism.java:550)
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareSelectAllRows(ExpressionQueryMechanism.java:1722)
org.eclipse.persistence.queries.ReadAllQuery.prepareSelectAllRows(ReadAllQuery.java:885)
org.eclipse.persistence.queries.ReadAllQuery.prepare(ReadAllQuery.java:816)
org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:666)
org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:911)
org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:615)
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:872)
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473)
rest.AbstractFacade.findByStateID(AbstractFacade.java:51)
rest.CitiesFacadeREST.findByState(CitiesFacadeREST.java:49)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:205)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:186)
org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)
org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:205)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:186)
org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:236)
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:203)
org.apache.openejb.util.proxy.ProxyEJB$Handler.invoke(ProxyEJB.java:74)
rest.CitiesFacadeREST$$LocalBeanProxy.findByState(rest/CitiesFacadeREST.java)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.openejb.server.cxf.rs.OpenEJBEJBInvoker.performInvocation(OpenEJBEJBInvoker.java:95)
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:189)
org.apache.openejb.server.cxf.rs.OpenEJBEJBInvoker.invoke(OpenEJBEJBInvoker.java:68)
org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99)
org.apache.openejb.server.cxf.rs.AutoJAXRSInvoker.invoke(AutoJAXRSInvoker.java:64)
org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:254)
org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:251)
org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
note The full stack trace of the root cause is available in the Apache Tomcat (TomEE)/8.5.3 (7.0.1) logs.
Apache Tomcat (TomEE)/8.5.3 (7.0.1)
The querying uses by default java names. If you have doubt you can setup a jpa metamodel generator and you will be able to use a typed version of the attributes instead of strings.
because jpa/hibernate use propertynames and not column names you have to use private States stateId instead of private States state_Id.
So you have to Change equal(r.get("state_id"), id)) to equal(r.get("stateId"), id));
`

JPA StackOverflowError with recursive relationship

I am using Eclipselink to persist the following Entities (insignificant code left out):
#Entity
public class TestEntity {
#Id
#GeneratedValue
private int id;
#OneToMany(cascade = CascadeType.ALL, mappedBy="testEntity")
private List<OtherTestEntity> other = new ArrayList<OtherTestEntity>();
}
#Entity
#IdClass(OtherTestEntityPK.class)
public class OtherTestEntity {
public static class OtherTestEntityPK {
public int testEntity;
public int id;
}
#Id
#ManyToOne
private TestEntity testEntity;
#Id
#GeneratedValue
private int id;
#ManyToOne
private OtherTestEntity parent;
#OneToMany(mappedBy="parent")
private List<OtherTestEntity> childs = new ArrayList<OtherTestEntity>();
}
While trying to persist a TestEntity, I get the following error:
javax.persistence.PersistenceException: Exception [EclipseLink-28019] Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [anaflow] failed. Close all factories for this PersistenceUnit.
Internal Exception: java.lang.StackOverflowError
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createDeployFailedPersistenceException(EntityManagerSetupImpl.java:869)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:809)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:205)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:305)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:337)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:303)
at com.sap.anaflow.analysis.model.persistence.PersistenceManager.persist(PersistenceManager.java:17)
at com.sap.anaflow.analysis.model.persistence.PersistenceTest.testPersistence(PersistenceTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [anaflow] failed. Close all factories for this PersistenceUnit.
Internal Exception: java.lang.StackOverflowError
at org.eclipse.persistence.exceptions.EntityManagerSetupException.deployFailed(EntityManagerSetupException.java:239)
... 30 more
Caused by: java.lang.StackOverflowError
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.getMappingsByField(ObjectBuilder.java:3508)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.getMappingForField(ObjectBuilder.java:3486)
at org.eclipse.persistence.mappings.OneToOneMapping.getFieldClassification(OneToOneMapping.java:890)
at org.eclipse.persistence.mappings.OneToOneMapping.getFieldClassification(OneToOneMapping.java:894)
at org.eclipse.persistence.mappings.OneToOneMapping.getFieldClassification(OneToOneMapping.java:894)
----- Many, many more of these -----
Apart from that Error, I would like to know how to define a constraint that the childs and parents of one OtherTestEntity have the same TestEntity, so that the Database only needs to save a single id-mapping without the foreign key.
This is necessary because my real project contains a composite of 5 foreign keys.

getIdentifier method of PersistenceUnitUtil not working for Composite keys

I am getting below error when trying to retrieve identity using getIdentifier method of PersistenceUnitUtil. Is there anything I am doing wrong.
Local Exception Stack:
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: An internal error occurred accessing the primary key object [202].
Internal Exception: java.lang.NullPointerException
Descriptor: RelationalDescriptor(com.sample.Person --> [DatabaseTable(PERSON)])
at org.eclipse.persistence.exceptions.DescriptorException.errorUsingPrimaryKey(DescriptorException.java:1923)
at org.eclipse.persistence.internal.jpa.CMP3Policy$FieldAccessor.setValue(CMP3Policy.java:686)
at org.eclipse.persistence.descriptors.CMPPolicy.createPrimaryKeyInstance(CMPPolicy.java:453)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getIdentifier(EntityManagerFactoryImpl.java:75)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getIdentifier(EntityManagerFactoryDelegate.java:679)
at com.sample.PersistenceUtil.getEntityIdentifier(PersistenceUtil.java:27)
at com.sample.PersistenceUtil.getEntityIdentifier(PersistenceUtil.java:18)
at com.sample.OverrideUtilTest.canconfirmEntityEqualsforCompositeId2(OverrideUtilTest.java:147)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.CMP3Policy$FieldAccessor.setValue(CMP3Policy.java:682)
... 29 more
The code sample I am trying is this:
#Entity
#IdClass(PersonPK.class)
#Table(name = "PERSON")
public class Person {
#Id
#Column(name = "CODE_C")
private String code;
#Column(name = "NAME_C")
private String name;
#Id
#Column(name = "COUNTRY_C")
private String country;
public Person() {
}
public Person(String code, String country) {
this.code = code;
this.country = country;
}
public String getCode() {
return this.code;
}
public String getCountry() {
return this.country;
}
}
public class PersonPK implements Serializable {
private static final long serialVersionUID = 1L;
private final String code;
private final String country;
public PersonPK(String city, String country) {
super();
this.code = city;
this.country = country;
}
#Override
public boolean equals(Object object) {
return super.equals (object);
}
#Override
public int hashCode() {
return super.hashCode();
}
}
The code to retrieve identity I am using is
getEntityManagerFactory(persistenceUnitName).getPersistenceUnitUtil()
.getIdentifier(entity);
Any help is appreciated
The primary key class must be public and must have a public no-arg constructor.
Hibernate message in similar situation is a little bit more informative
javax.persistence.PersistenceException: org.hibernate.InstantiationException: No default constructor for entity: : PersonPK
Solution: Add default constructor to PersonPK

JPQLException : The state field path 't.id' cannot be resolved to a valid type

I am using eclipseLink and have the under mentioned query.
Query q = entityManager.createQuery("SELECT t FROM "
+ clazz.getName() + " t WHERE t.id = :id");
q.setParameter("id", id);
matchedEntity = (T) q.getSingleResult();
However only sometimes I get the following error
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [SELECT t FROM com.mt.igg.entities.CitizenRequest t WHERE t.id = :id].
[57, 61] The state field path 't.id' cannot be resolved to a valid type.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1585)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
at com.sun.proxy.$Proxy94.createQuery(Unknown Source)
The code works sometimes, and only sometimes I get the above error.
The case of the fields in query is same as that in the entity.
I am using tomcat server to deploy the project
Edit: The CitizenRequest entity:
#Entity
#Table(name = "CITIZEN_REQUEST")
#Multitenant
#TenantDiscriminatorColumn(name = "TENANT_ID", contextProperty = PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)
public class CitizenRequest implements Serializable {
// id of CitizenRequest
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "ID")
private Integer id;
// Title of CitizenRequest
#Column(name = "TITLE_ID")
#NotNull
private Integer title;