Error in JPA Find Method in JavaEE

Asked 2 years ago, Updated 2 years ago, 101 views

On wildFly (Ver.8.2.0.Final), we are verifying the operation of data access using JPA's ecipselink (Ver.2.5.1).

@Stateful(name="PersonalInformationDaoBeanEJB")
public class PersonalInformationDaoBean implements Serializable {

private EntityManagerFactory entityManagerFactory;
private EntityManager;

public PersonalInformationDaoBean(){
}

public void connect(){
    This.entityManagerFactory=Persistence.createEntityManagerFactory("persistenceUnit");
    This.entityManager=entityManagerFactory.createEntityManager();
}

publicObject loadSingleData(ClassityClass, int primaryKey){
    try{
        returnityManager.find(entityClass, primaryKey);
    } catch(Exceptionex){
        return null;
    }
}

By invoking each method in this class,
I would like to create EntityManager Factory and EntityManager and retrieve data to DB.
When calling the JPA framework find method, two exceptions occur at random:

 · org.h2.jdbc.JdbcSQLException: Schema "SAMPLE" not found.
·Unknown entity bean class: class Entity. PersonalInformationEntity, please verify that this class has been marked with the @Entity announcement.

Incidentally, I have attached schema information to persistence.xml and @Entity to PersonalInformationEntity.
From this point of view, there may be other causes, but we have not been able to identify the current situation.
What are the possible causes?

Also, list the persistence.xml corresponding to the database below.
The database uses postgreSQL and the columns to be retrieved have already been created in the database.

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"
<persistence-unit name="persistenceUnit">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>Entity.PersonalInformationEntity</class>
    <properties>
        <property name="eclipselink.jdbc.url" value="jdbc:postgresql://localhost:5432/sample"/>
        <property name="eclipselink.jdbc.driver" value="org.postgresql.Driver"/>
        <property name="eclipselink.jdbc.user" value="dummyUser"/>
        <property name="eclipselink.jdbc.password" value="dummyPass"/>
    </properties>
</persistence-unit>
</persistence>

java java-ee jpa

2022-09-30 20:47

1 Answers

Self-resolved.

Persistence.xml Properties
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/sample"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.user" value="dummyUser"/>
<property name="javax.persistence.jdbc.password" value="dummyPass"/>

When I changed to , Exception was

javax.resource.ResourceException:IJ000460:Error checking for a transaction

changed to , so when I searched the web, JBossDeveloper stated that the transaction type must be "RESOURCE_LOCAL", so
After adding transaction-type="RESOURCE_LOCAL" to the end of persistence-unit,
You can now get an entity that matches the primary key.


2022-09-30 20:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.