I am trying to persist some data in my JavaFX application.
My code fails when attempting to create a table in my PersistenceManager class:
private final static String DATABASE_URL = "jdbc:sqlite:my.db";
private final static String DATABASE_DRIVER = "org.sqlite.JDBC";
// ...
Class.forName(DATABASE_DRIVER);
DriverManager.getConnection(DATABASE_URL);
connectionSource = new JdbcConnectionSource(DATABASE_URL);
// here it fails:
TableUtils.createTable(connectionSource,MyClass.class);
A file my.db is actually created, but it is empty. When executing TableUtils.createTable, it triggers the following:
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
... 43 more
Caused by: java.lang.AbstractMethodError: com.j256.ormlite.jdbc.JdbcDatabaseConnection.compileStatement(Ljava/lang/String;Lcom/j256/ormlite/stmt/StatementBuilder$StatementType;[Lcom/j256/ormlite/field/FieldType;I)Lcom/j256/ormlite/support/CompiledStatement;
at com.j256.ormlite.table.TableUtils.doStatements(TableUtils.java:458)
at com.j256.ormlite.table.TableUtils.doCreateTable(TableUtils.java:441)
at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:221)
at com.j256.ormlite.table.TableUtils.createTable(TableUtils.java:54)
at org.lh.mypackage.mysubpackage.PersistenceManager.<init>(PersistenceManager.java:32)
My Class is this:
#DatabaseTable(tableName = "myclass")
public class MyClass {
#DatabaseField(id = true)
private String nome;
#ForeignCollectionField(eager = false)
private Collection<MyOtherClass> risposte;
protected MyClass() {
super();
}
}
and MyOtherClass is:
#DatabaseTable(tableName = "myotherclass")
public class MyOtherClass {
#DatabaseField(id = true)
private String nome;
#DatabaseField(foreign = true)
private MyClass scheda;
protected MyOtherClass() {
super();
}
}
I am using ormlite-core-4.49-SNAPSHOT.jar.
What should I look for correcting this?
For me solution has been to switch to ormlite-core-4.48. Same version for ormlite-jdbc driver. Now it works correctly.
Related
I am using a Cassandra Repository to fetch data from the database.
I use the following query (to be as simple as possible):
public interface PersonReposiroty extends CassandraRepository<Person>
#Query("SELECT * FROM KeySp.person WHERE joinTime >= 21 ALLOW FILTERING")
public List<Person> findByTime();
}
When this is called by the Java statement :
List<Person> persons = repository.findByTime();
It produces a NullPointerException.
In fact, any query that should return any data from the DB shows the Exception.
At the same time Update, Delete, Save functions work perfectly when implemented using the above repository.
Please tell me where am I going wrong and how to get it done. (I use Spring Boot)
THANKS in Advance.
My Person Entity is :
#Entity
#Table(name = "person", indexes = { #Index(name="peson_index", columnList = "joinTime, category, personId") })
public class Person {
#Id
#PrimaryKeyColumn
private PersonContext context;
#Column(name = "address", columnDefinition = "LONGTEXT")
private String address;
public PersonContext getContext() {
return context;
}
public void setContext(PersonContext context) {
this.context = context;
}
public String getAddress() {
return adress;
}
public void setAddress(String address) {
this.address = address;
}
}
And PersonContext.java is
#Embeddable
#PrimaryKeyClass
public class PersonContext implements Serializable {
private static final long serialVersionUID = 3L;
#NotNull
#PrimaryKeyColumn(name = "joinTime", type = PrimaryKeyType.PARTITIONED)
private long joinTime;
#NotNull
#Column(name = "category")
private String category;
#Column(name = "person_id", length = 50)
private String personId = StringUtils.EMPTY;
public long getjoinTime() {
return joinTime;
}
public void setjoinTime(long joinTime) {
this.joinTime = joinTime;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getPersonId() {
return personId;
}
public void setPersonId(String personId) {
this.personId = personId;
}
}
Stack Trace:
ForgivingExceptionHandler: Consumer com.User.service.CacheService$1#6e6c7b7a (amq.ctag-6VuMjQcL3vjdfed2yC78zA) method handleDelivery for channel AMQChannel(amqp://user#155.83.167.923:5672/,1) threw an exception for channel AMQChannel(amqp://guest#159.89.169.123:5672/,1)
java.lang.NullPointerException: null
at org.springframework.data.cassandra.convert.MappingCassandraConverter.readProperty(MappingCassandraConverter.java:259)
at org.springframework.data.cassandra.convert.MappingCassandraConverter$1.doWithPersistentProperty(MappingCassandraConverter.java:233)
at org.springframework.data.cassandra.convert.MappingCassandraConverter$1.doWithPersistentProperty(MappingCassandraConverter.java:229)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:330)
at org.springframework.data.cassandra.convert.MappingCassandraConverter.readProperties(MappingCassandraConverter.java:229)
at org.springframework.data.cassandra.convert.MappingCassandraConverter.readPropertiesFromRow(MappingCassandraConverter.java:223)
at org.springframework.data.cassandra.convert.MappingCassandraConverter.readEntityFromRow(MappingCassandraConverter.java:190)
at org.springframework.data.cassandra.convert.MappingCassandraConverter.readRow(MappingCassandraConverter.java:176)
at org.springframework.data.cassandra.convert.MappingCassandraConverter.read(MappingCassandraConverter.java:298)
at org.springframework.data.cassandra.core.CassandraConverterRowCallback.doWith(CassandraConverterRowCallback.java:47)
at org.springframework.data.cassandra.core.CassandraTemplate.processResultSet(CassandraTemplate.java:605)
at org.springframework.data.cassandra.core.CassandraTemplate.select(CassandraTemplate.java:594)
at org.springframework.data.cassandra.core.CassandraTemplate.select(CassandraTemplate.java:376)
at org.springframework.data.cassandra.repository.query.CassandraQueryExecution$CollectionExecution.execute(CassandraQueryExecution.java:85)
at org.springframework.data.cassandra.repository.query.CassandraQueryExecution$ResultProcessingExecution.execute(CassandraQueryExecution.java:143)
at org.springframework.data.cassandra.repository.query.AbstractCassandraQuery.execute(AbstractCassandraQuery.java:113)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:483)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy142.findByResource(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy142.findByTime()
at User.StatisticsCacheService.storeDataInternal(StatisticsCacheService.java:46)
at User.CacheService$1.handleDelivery(CacheService.java:54)
at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)
at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
2018-10-31 13:02:48,193 ERROR [User-scheduler-2] TaskUtils$LoggingErrorHandler: Unexpected error occurred in scheduled task.
com.rabbitmq.client.AlreadyClosedException: channel is already closed due to clean channel shutdown; protocol method: #method<channel.close>(reply-code=200, reply-text=Closed due to exception from Consumer (amq.ctag-6VuMjQcL3vjdfed2yC78zA) method handleDelivery for channel AMQChannel(amqp://guest#159.89.169.123:5672/,1), class-id=0, method-id=0)
at com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(AMQChannel.java:253)
at com.rabbitmq.client.impl.AMQChannel.rpc(AMQChannel.java:336)
at com.rabbitmq.client.impl.ChannelN.basicConsume(ChannelN.java:1365)
at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.basicConsume(AutorecoveringChannel.java:540)
at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.basicConsume(AutorecoveringChannel.java:494)
at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.basicConsume(AutorecoveringChannel.java:472)
at User.service.CacheService.cacheDataInternal(CacheService.java:59)
at User.service.periodic.StatisticsCacheService.cacheData(StatisticsCacheService.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
I'm learning Spring framework and using DAO. When I use my dao.save method to persist new object to database I got NullPointerException. How can i solve this problem and correctly persist/delete/update objects to databases ? Thanks.
Entity Coffee.class :
#Entity
public class Coffee {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String coffeeName;
private Integer costForCup;
private boolean isDisabled;
#OneToMany(mappedBy = "coffee")
private Set<Coffee> coffee;
public Coffee() {}
public Coffee(String coffeeName, Integer costForCup, boolean isDisabled) {
this.coffeeName = coffeeName;
this.costForCup = costForCup;
this.isDisabled = isDisabled;
}
*getters and setters*
CoffeeDAO :
public interface CoffeeDAO {
public Coffee findById(Long id);
public List<Coffee> findAll();
public void createCoffee(Coffee coffee);
}
CoffeeDAOImpl :
public class CoffeeImplementation implements CoffeeDAO {
private HibernateTemplate hibernateTemplate;
public void setSessionFactory(SessionFactory sessionFactory){
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
***
#Override
#Transactional
public void createCoffee(Coffee coffee) {
hibernateTemplate.save(coffee);
}
}
OrderBean.class :
#ManagedBean
#SessionScoped
public class OrderBean {
#Autowired
private CoffeeDAO coffeeDAO;
public boolean createCoffee(){
Coffee coffee = new Coffee("Кофе", 4, true);
System.out.println(coffee.getCoffeeName()+" " + coffee.getCostForCup() + " " + coffee.isDisabled());
coffeeDAO.createCoffee(coffee);
return true;
}
Error logs:
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 32 more
Caused by: java.lang.NullPointerException
at javacoff.beans.OrderBean.createCoffee(OrderBean.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 33 more
Solve my problem with SpringBeanAutowiringSupport in my managed bean:public class OrderBean extends SpringBeanAutowiringSupport.
I'm writing a query for the following domain model
#QueryEntity
public class Person
{
...
private String name;
private List<String> addresses;
...
}
And I wish to have the query result return to me a representation of a person as there are too much other fields that I do no care about.
public class PersonRepresentation
{
private string name;
private List<String> addresses;
#QueryProjection
public PersonRepresentation(String name, List<String> addresses){
this.name = name;
this.addresses = addresses;
}
...
}
When I attempt to create my JPA query as such
private final QPersonRepresentation qPersonRepresentationProjection = new QPersonRepresentation(
qPerson.name,
qPerson.addresses
);
List<PersonRepresentation> result = new JPAQuery(em)
.from(qPerson)
.list(qPersonRepresentationProjection);
I get the following error:
java.lang.IllegalArgumentException: org.hibernate.QueryException: not
an entity [select person.name,
person.addresses from
com.example.foo.Person person]
at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1750)
at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1683)
at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:331)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
....
I've scurred both the documentation and the tests on the github and so far cannot come up with a reason why I cannot execute this query.
I am trying to get a user based on their ID using this named query, however I keep getting an illegal argument exception. I've been looking at this code for awhile. Hopefully someone may catch something I might've missed.
This is my ORM
#Entity
#Table(name = "MYUSER")
#XmlRootElement
#NamedQueries({
#NamedQuery(name = "Myuser.findAll", query = "SELECT m FROM Myuser m"),
#NamedQuery(name = "Myuser.findByUserid", query = "SELECT m FROM Myuser m WHERE m.userid = :userid"),
#NamedQuery(name = "Myuser.findByName", query = "SELECT m FROM Myuser m WHERE m.name = :name"),
#NamedQuery(name = "Myuser.findByPassword", query = "SELECT m FROM Myuser m WHERE m.password = :password"),
#NamedQuery(name = "Myuser.findByEmail", query = "SELECT m FROM Myuser m WHERE m.email = :email"),
#NamedQuery(name = "Myuser.findByTel", query = "SELECT m FROM Myuser m WHERE m.tel = :tel"),
#NamedQuery(name = "Myuser.findByAddress", query = "SELECT m FROM Myuser m WHERE m.address = :address"),
#NamedQuery(name = "Myuser.findBySecqn", query = "SELECT m FROM Myuser m WHERE m.secqn = :secqn"),
#NamedQuery(name = "Myuser.findBySecans", query = "SELECT m FROM Myuser m WHERE m.secans = :secans")})
public class Myuser implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#Basic(optional = false)
#Column(name = "USERID")
private Integer userid;
#Column(name = "NAME")
private String name;
#Column(name = "PASSWORD")
private String password;
#Column(name = "EMAIL")
private String email;
#Column(name = "TEL")
private Integer tel;
#Column(name = "ADDRESS")
private String address;
#Column(name = "SECQN")
private String secqn;
#Column(name = "SECANS")
private String secans;
public Myuser() {
}
public Myuser(Integer userid) {
this.userid = userid;
}
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getTel() {
return tel;
}
public void setTel(Integer tel) {
this.tel = tel;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getSecqn() {
return secqn;
}
public void setSecqn(String secqn) {
this.secqn = secqn;
}
public String getSecans() {
return secans;
}
public void setSecans(String secans) {
this.secans = secans;
}
#Override
public int hashCode() {
int hash = 0;
hash += (userid != null ? userid.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 Myuser)) {
return false;
}
Myuser other = (Myuser) object;
if ((this.userid == null && other.userid != null) || (this.userid != null && !this.userid.equals(other.userid))) {
return false;
}
return true;
}
#Override
public String toString() {
return "ejbentity.Myuser[ userid=" + userid + " ]";
}
}
This is my user facade
#Stateless
public class MyuserFacade implements MyuserFacadeRemote {
#PersistenceContext(unitName = "EJBServer-ejbPU")
private EntityManager em;
protected EntityManager getEntityManager() {
return em;
}
public MyuserFacade() {
//super(Myuser.class);
}
#Override
public Myuser getUser(int userID) {
Myuser aUser = new Myuser();
aUser = (Myuser)em.createNamedQuery("Myuser.findByUserid").setParameter("userid", userID).getResultList();
return aUser;
}
}
My persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="EJBEntityPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<!--<exclude-unlisted-classes>false</exclude-unlisted-classes>-->
<class>ejbentity.Myuser</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/EA"/>
<property name="javax.persistence.jdbc.password" value="test"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.user" value="test"/>
</properties>
</persistence-unit>
</persistence>
Error Log is given below:
java.lang.reflect.InvocationTargetException
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.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:446)
at org.glassfish.appclient.client.AppClientFacade.main(AppClientFacade.java:166)
Caused by: javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:752)
at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:702)
at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:507)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79)
at com.sun.proxy.$Proxy266.getUser(Unknown Source)
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 com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496)
at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
Caused by: java.lang.IllegalArgumentException: NamedQuery of name: Myuser.findByUserid not found.
at org.eclipse.persistence.internal.jpa.QueryImpl.getDatabaseQueryInternal(QueryImpl.java:355)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1135)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:522)
at stateless.MyuserFacade.getUser(MyuserFacade.java:62)
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.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4786)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:656)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
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 com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
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 com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:205)
... 19 more
Java Result: 1
Actual error:
Caused by: java.lang.IllegalArgumentException: NamedQuery of name: Myuser.findByUserid not found.
Happens from:
#NamedQuery(name = "Myuser.findByUserid", query = "SELECT m FROM Myuser m WHERE m.userid = :userid"),
UPDATE:
From your persistence.xml:
<persistence-unit name="EJBEntityPU" transaction-type="RESOURCE_LOCAL">
Here you are using transaction-type="RESOURCE_LOCAL". So if you use it, then you are responsible for EntityManager.
Then you must have to follow (JPA Concepts: JPA 101)
You must use the EntityManagerFactory to get an EntityManager
The resulting EntityManager instance is a PersistenceContext/Cache
An EntityManagerFactory can be injected via the #PersistenceUnit
annotation only (not #PersistenceContext)
You are not allowed to use #PersistenceContext to refer to a unit of
type RESOURCE_LOCAL
You must use the EntityTransaction API to begin/commit around every
call to your EntityManger
Calling entityManagerFactory.createEntityManager() twice results in
two separate EntityManager instances and therefor two separate
PersistenceContexts/Caches.
It is almost never a good idea to have more than one instance of an
EntityManager in use (don't create a second one unless you've
destroyed the first)
Solution:
This is an example. you can follow the tutorial if you want to use RESOURCE_LOCAL.
Related Link:
DON'T USE JPA'S RESOURCE_LOCAL ON THE SERVER
Persistence unit as RESOURCE_LOCAL or JTA?
persistence.xml different transaction-type attributes
We got the same error and it was because the entities were missing in persistence.xml
In your persistence.xml is:
<persistence-unit name="EJBEntityPU"
but in your MyuserFacade you use:
#PersistenceContext(unitName = "EJBServer-ejbPU")
You should change that to:
#PersistenceContext(unitName = "EJBEntityPU")
I notice you have class ejbentity.Myuser in your persistence.xml. The class actually lives in a package structure consisting of one directory called "ejbentity"? The stacktrace suggests that your Myuser class with the NamedQuery annotations is not being found, which would be explained if your package structure is not being loaded as you expect.
I don't think that transaction-type has anything to do with #NamedQuery annotation.
This error
Caused by: java.lang.IllegalArgumentException: NamedQuery of name: Myuser.findAll not found.
at org.eclipse.persistence.internal.jpa.QueryImpl.getDatabaseQueryInternal(QueryImpl.java:355)
looks like an EclipseLink bug. Which version are you using ?
I'm developing a vaadin application and now have the following trouble.
I'm trying to bind a nested property along BeanFieldGroup.
MyEntity Class
#Entity
public class MyEntity implements Serializable {
private static final long serialVersionUID = 1L;
#EmbeddedId
private MyEntityPK id;
//Others Property
public MyEntityPK getId() {
return this.id;
}
public void setId(MyEntityPK id) {
this.id = id;
}
}
MyEntityPK Class
#Embeddable
public class MyEntityPK implements Serializable {
#Column(name="CD_VARIABILE")
private String cdVariabile;
public String getCdVariabile() {
return this.cdVariabile;
}
public void setCdVariabile(String cdVariabile) {
this.cdVariabile = cdVariabile;
}
}
MyVaadinPanel
private BeanFieldGroup<MyEntity> binder;
binder = new BeanFieldGroup<MyEntity>(MyEntity.class);
binder.setItemDataSource(new BeanItem<MyEntity>(new MyEntity()));
variabileBinder.bind(new TextField(), "id.cdVariabile");
When, I try to bind the property "id.cdVariabile" to TextFiel, I get the following error:
Caused by: com.vaadin.data.util.MethodProperty$MethodException
at com.vaadin.data.util.NestedMethodProperty.getValue(NestedMethodProperty.java:205)
at com.vaadin.data.util.TransactionalPropertyWrapper.getValue(TransactionalPropertyWrapper.java:73)
at com.vaadin.ui.AbstractField.getDataSourceValue(AbstractField.java:299)
at com.vaadin.ui.AbstractField.setPropertyDataSource(AbstractField.java:629)
... 48 more
Caused by: java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.data.util.NestedMethodProperty.getValue(NestedMethodProperty.java:201)
... 51 more
Where am I wrong ?
Looks like when you create your entity in binder.setItemDataSource(new BeanItem<MyEntity>(new MyEntity())); its id is null, hence trying to rerieve id.cdVariabile would result in NPE.
Try adding a PK:
BeanFieldGroup<MyEntity> binder;
binder = new BeanFieldGroup<MyEntity>(MyEntity.class);
MyEntity myEntity = new MyEntity();
myEntity.setId(new MyEntityPK());
binder.setItemDataSource(new BeanItem<MyEntity>(myEntity));
binder.bind(new TextField(), "id.cdVariabile");