Hibernate Table not found, MappingException and AssertionException - java

I tried to map an existing Postgresql Database with Hibernate and it already worked while I didn't add Inheritances per Subclass to Hibernate
This is the superclass
#Entity
#Table(name = "place", schema = "public", catalog = "dbp")
#Inheritance(strategy = InheritanceType.JOINED)
public class PlaceEntity {
private long id;
private String name;
private String url;
// private CityEntity cityById;
private ContinentEntity continentById;
private CountryEntity countryById;
And this is the subclass
#Entity
#Table(name = "city", schema = "public", catalog = "dbp")
#PrimaryKeyJoinColumn(name = "cityid", referencedColumnName = "id")
public class CityEntity extends PlaceEntity{ //WHEN I ADD extends PlaceEntity , THE ERROR OCCURES
private Long cityid;
private Long ispartof;
//private PlaceEntity placeByCityid;
private CountryEntity countryByIspartof;
private Collection<PersonEntity> peopleByCityid;
private Collection<UniversityEntity> universitiesByCityid;
Then Intellij throughs the following exception:
INFO: HHH000270: Type registration [java.util.UUID] overrides previous :org.hibernate.type.UUIDBinaryType#63a12c68
Sep 25, 2017 6:56:11 PM org.hibernate.AssertionFailure <init>
ERROR: HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: Table dbprak24.public.place not found
Sep 25, 2017 6:56:11 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:postgresql://localhost:5432/dbprak24]
java.lang.ExceptionInInitializerError
at Main.<clinit>(Main.java:22)
Caused by: org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.JoinedSubclassEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:112)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:128)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:297)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
at Main.<clinit>(Main.java:20)
Caused by: org.hibernate.AssertionFailure: Table dbprak24.public.place not found
at org.hibernate.persister.entity.AbstractEntityPersister.getTableId(AbstractEntityPersister.java:5231)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:433)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
... 7 more
Exception in thread "main"
Process finished with exit code 1
I already searched for related problems but couldn't find any solution.
I'd be very glad if anyone could help me :)
Always when i delete
extends PlaceEntity
it runs smoothly and it maps als Tables, place included.
I already invested several days in that problem ^^
Sorry for the strange english, it's not my foreign language :)
Nice evening fellows
Eisenbahnplatte

I have faced the same issue (or something very similiar).
Hibernate 5.2.17.Final + PostgreSQL + Inheritance.JOINED.
Solved it by removing "catalog" attribute from mapping. Try to replace
#Table(name = "place", schema = "public", catalog = "dbp")
with
#Table(name = "place", schema = "public")
Hope this helps.

Related

Unable to find column with logical name in org.hibernate.mapping.Table and its related supertables and secondary tables

When I try to run my Application Class it gives me the following error:
2021-04-26 16:20:47.551 ERROR 14416 --- [ main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: Unable to find column with logical name: property_id in org.hibernate.mapping.Table(property) and its related supertables and secondary tables
From looking at that it feels to me like I might've named it incorrectly, but even when I went into the table and copied field names directly it didn't fix the issue.
The Property entity is as follows:
#Entity
#Table(name = "property")
public class Property {
#Id
#OneToOne
#JoinColumn(name = "property_id", referencedColumnName = "property_id")
private Address address;
// other fields
With its table structure being:
While the Address entity it's connected to is:
#Entity
#Table(name = "address")
public class Address {
#Id
#GeneratedValue
#Column(name = "property_id")
private Long propertyID;
// other fields
With table structure:
As you can see I have the names correct, and I believe my datasource is correctly formatted, if I use a column name that isn't in the table IntelliJ throws a warning saying it cannot resolve the column, which I don't get as they're written now.
This is my first big project using JPA so I might be missing something obvious but any help would be much appreciated, I've looked at other solutions and tried some of the suggestions but they all seem to be slightly different and not applicable to what I'm trying. Any help would be greatly appreciated :)
#Entity
#Table(name = "property")
public class Property {
#Id
private Long id;
#OneToOne
#MapsId
#JoinColumn(name="property_id")
private Address address;
...
}
#Entity
#Table(name = "address")
public class Address {
#Id
#GeneratedValue
#Column(name = "property_id")
private Long propertyID;
...
}
See the Hibernate ORM documentation for Derived Identifiers.

javax.ejb.EJBException: java.rmi.MarshalException

My question is with regards to error messages when i try to create or even view the credit package.
This is the error message that i encountered in glassfish.
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'ABOUT' in 'field list'
Error Code: 1054
Call: SELECT CREDITID, ABOUT, CREDITS, NAME, PACKAGECODE FROM CREDITPACKAGE
Query: ReadAllQuery(referenceClass=CreditPackage sql="SELECT CREDITID, ABOUT, CREDITS, NAME, PACKAGECODE FROM CREDITPACKAGE")
Error message from my own admin client
Caused by: javax.ejb.EJBException: java.rmi.MarshalException: CORBA MARSHAL 1330446393 Maybe; nested exception is:
org.omg.CORBA.MARSHAL: WARNING: 00810057: Could not load class com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException vmcid: OMG minor code: 57 completed: Maybe
at ejb.session.stateless._CreditPackageControllerRemote_Wrapper.retrieveAllCreditPackage(ejb/session/stateless/_CreditPackageControllerRemote_Wrapper.java)
The columns are accounted for, but i'm not sure why it says that unknown column 'ABOUT' in 'field list'
#Entity
public class CreditPackage implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long creditId;
#Column(unique = true)
private String packageCode;
#Column(length = 32, nullable = false)
private String name;
#Column(length = 32, nullable = false)
private String about; //already tried escaping the column name using `` and backslashes
#Column(nullable = false, precision = 18, scale = 4)
private BigDecimal credits;
}
This method is in the controller sessionbean
#Override
public List<CreditPackage> retrieveAllCreditPackage() {
Query query = em.createQuery("SELECT s FROM CreditPackage s"); //Not too sure if this is correct
return query.getResultList();
}
Thank you for reading this! Hopefully there is someone that can help me to resolve this.
Managed to resolve this question with others help.
Turns out i did not regenerate the JDBC database when i added some new columns so the old columns are still there. Hence the exception.
So what i did was:
Delete all the tables in the JDBC database
Redeployed my application system
Run my application client.
Then the error is resolved because it regenerates the new tables in JDBC database according to the new columns.
Hope that it will be helpful to others. Thank you for reading this. :)

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails

I'm constantly getting error when i wanna insert some data
Project Class
#Entity
#NamedQueries({
#NamedQuery(name = "Project.findAll",
query = "SELECT p FROM Project p"),
#NamedQuery(name = "Project.findByTitle",
query = "SELECT p FROM Project p WHERE p.title = :title")
})
public class Project implements Serializable{
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int projectId;
#Column
private String title;
#Column
private String description;
#Column
private Date projectDate;
#ManyToOne
#JoinColumn(name = "projectStatusId")
private ProjectStatus projectStatus;
#OneToMany(mappedBy = "projectMemberId",fetch = FetchType.EAGER)
private List<ProjectMember> memberList = new ArrayList<ProjectMember>();
/**
* Setters and Getters
*/
}
ProjectMember Class
#Entity
#NamedQueries({
#NamedQuery(name = "ProjectMember.findAll",
query = "SELECT pm FROM ProjectMember pm"),
#NamedQuery(name = "ProjectMember.findByProject",
query = "SELECT pm FROM ProjectMember pm WHERE pm.project = :project"),
#NamedQuery(name = "ProjectMember.findByUser",
query = "SELECT pm FROM ProjectMember pm WHERE pm.user = :user"),
#NamedQuery(name = "ProjectMEmeber.findByUserAndProject",
query = "SELECT pm FROM ProjectMember pm WHERE pm.user = :user AND pm.project = :project")
})
public class ProjectMember implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int projectMemberId;
#Column
private Date activationDate;
#Column
private Date lastActiveDate;
#ManyToOne
#JoinColumn(name = "memberStatusId")
private MemberStatus memberStatus;
#ManyToOne
#JoinColumn(name = "projectId")
private Project project;
#ManyToOne
#JoinColumn(name = "memberRoleId")
private MemberRole memberRole;
#ManyToOne
#JoinColumn(name = "userId")
private User user;
/**
* Setter and Getter
*/
}
that's how i run it
ProjectController Class
public String createProject(){
project.setProjectDate(new Date());
project.setProjectStatus(new ProjectStatusFacade().findByStatus("active"));
ProjectMember projectMember = new ProjectMember();
projectMember.setMemberStatus(new MemberStatusFacade().findByStatus("accepted"));
projectMember.setMemberRole(new MemberRoleFacade().findByRole("team leader"));
projectMember.setActivationDate(new Date());
projectMember.setUser(userSession.getUser());
new ProjectFacade().create(project);
System.out.print(project);
projectMember.setProject(project);
new ProjectMemberFacade().create(projectMember);
userSession.setUser(new UserFacade().findById(userSession.getUser().getUserId()));
return "index?faces-redirect=true";
}
and that's what i get in the end
Caused by: javax.faces.el.EvaluationException: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
... more exceptions
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
... more exceptions
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
...more exceptions
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`goent`.`projectmember`, CONSTRAINT `FKfyw2iinfhhsbrmqbu1sr7l93q` FOREIGN KEY (`projectMemberId`) REFERENCES `project` (`projectId`))
... more exceptions
15:51:06,449 ERROR [io.undertow.request] (default task-4) UT005023: Exception handling request to /hibernate/pages/project-add-member.xhtml: javax.servlet.ServletException: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
... more exceptions
Caused by: javax.faces.el.EvaluationException: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
... more exceptions
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement
...more exceptions
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
... more exceptions
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`goent`.`projectmember`, CONSTRAINT `FKfyw2iinfhhsbrmqbu1sr7l93q` FOREIGN KEY (`projectMemberId`) REFERENCES `project` (`projectId`))
... more exceptions
Using: Java, JPA, Hibernate, MySQL5.7
The cause of exception is :
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`goent`.`projectmember`, CONSTRAINT `FKfyw2iinfhhsbrmqbu1sr7l93q` FOREIGN KEY (`projectMemberId`) REFERENCES `project` (`projectId`))
Your action is violating foreign key constraint for projectMemberId column in projectmember table, which is referencing projectId column of project table as per your defined specifications.
This is what most likely is happening.
In the Project entity, you are telling the persistence provider to always eagerly fetch the ProjectNames:
#OneToMany(mappedBy = "projectMemberId",fetch = FetchType.EAGER)
private List<ProjectMember> memberList = new ArrayList<ProjectMember>();
Then in the save method you are creating a ProjectName and populating it with the Project. Thats fine, though the list in the Project does not contain that newly created ProjectName.
The dependency has to be set on both sides, so eventually you would need to do following in your method:
project.getMemberList().add(projectName);
Thank you people, finally I could fix the bug. The problem was in Project class, it was about incorrect mapping. Instead of telling variable to map in other class, I was pointing on PK of that class.
I wrote this
Project class
#ManyToOne
#JoinColumn(name = "projectStatusId")
private ProjectStatus projectStatus;
instead this
//Correct code
#ManyToOne
#JoinColumn(name = "project")
private ProjectStatus projectStatus;
after this change the code started work well.

SQLServerException when persisting entity - index is out of range

I'm having problems persisting an entity with a #OneToOne relationship with another entity. We've recently upgraded to Java 8 with Spring 4 and Hibernate 4 so I'm sure there's some annotation or configuration that has changed.
Relevant code
PermitState.java:
#Entity
#Table(schema = "dbo", name = "PermitState")
public class PermitState implements Serializable {
private String oid;
private Permit permit;
private Integer invoiced;
private Integer used;
private Integer ordered;
private String permitId;
#OneToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "PERMITID")
public Permit getPermit() {
return permit;
}
#Id
#Column(name = "PERMITID", nullable = true, length = 8,insertable = false,updatable = false)
public String getPermitId() {
return permitId;
}
... more getters and setters (irrelevant)
Permit.java:
#Entity
#Table(schema = "dbo")
public class Permit {
private String permitid;
private PermitState permitState;
...some more attributes, irrelevant
#Id
#Column(name = "PERMITID", length = 8)
public String getPermitid() {
return permitid;
}
#OneToOne(mappedBy="permit", cascade=CascadeType.ALL,fetch = FetchType.LAZY)
public PermitState getPermitState() {
return permitState;
}
Stacktrace
Caused by: org.hibernate.exception.GenericJDBCException: could not insert: [dao.srs.model.PermitState]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3099)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3521)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:395)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:387)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:303)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:349)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1195)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:75)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:515)
... 65 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The index 6 is out of range.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setterGetParam(SQLServerPreparedStatement.java:700)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setValue(SQLServerPreparedStatement.java:709)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setString(SQLServerPreparedStatement.java:1034)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setString(NewProxyPreparedStatement.java:963)
at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$1.doBind(VarcharTypeDescriptor.java:57)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:93)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:284)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:279)
at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:343)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrateId(AbstractEntityPersister.java:2835)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2804)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3076)
... 78 more
As you can see, the PermitState entity has both a relation to Permit (via PERMITID, which is the PK in Permit) AND a field called PermitId, which is supposed to the connected Permit's ID. This doesn't seem to work though, it seems that it's trying to insert all 6 attributes even though Permit shouldn't be inserted into the database. I tried to annotate Permit in PermitState with #Transient, but then I get a AnnotationException:
Caused by: org.hibernate.AnnotationException: Unknown mappedBy in: dao.srs.model.Permit.permitState, referenced property unknown: dao.srs.model.PermitState.permit
Any help would be greatly appreciated!
Update
Just to clarify, the DB only have 5 fields - OID, PERMITID, INVOICED, USED and ORDERED - which is why I'm thinking its trying to insert the Permit entity as well. The exact same code without modifications worked when we used Java 7, Spring 3, hibernate-annotations 3.3.1.GA and hibernate-entitymanager 3.3.2.GA. We now use Java 8, Spring 4 and Hibernate core+entitymanager+ehcache 4.2.19.
It seem to me, judging from the exception, that you tried #Transient while still having the #OneToOne and #JoinColumn. That does not really make sense, as you tell Hibernate you want to handle it yourself and that it should handle it also.
Also I find it a bit confusing you both have the Permit entity and the permitId in PermitState. You tell it that you don't want to update permitId, but you still use it as the join column?
I recommend removing the permitId and only have the Permit entity in PermitState. You can still have the getPermitId method if you like, but treat it as an agregate instead.
If all else fails try and log the SQL generated by Hibernate to see what is going on. Perhaps pasting it for us to see.
I think I solved it. I'm still not entirely sure why this works, but it does:
I removed PermitId (the String property) from PermitState.java, and instead used the PermitId from the Permit entitiy in PermitState.
It looks like this:
Permit.java:
private String permitid;
private PermitState permitState;
#OneToOne(mappedBy="permit", cascade=CascadeType.ALL,fetch = FetchType.LAZY)
public PermitState getPermitState() {
return permitState;
}
PermitState.java
private Permit permit;
#OneToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "PERMITID")
public Permit getPermit() {
return permit;
}
Thanks Martin and Bilbo for your help.

Error on compiling query: The abstract schema type 'entity' is unknown

I'm developing a game with a database connection, and I use JPA to persist my data. Here is my Game entity :
#Entity
#Table(name = "game")
public class Game implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "game_id")
private int id;
#Column(name = "name")
private String name;
#Column(name = "nbTurns")
private int nbTurns;
#Column(name = "playedOn")
#Temporal(TemporalType.TIMESTAMP)
private Date playedOn;
#ElementCollection(fetch = FetchType.EAGER)
#CollectionTable(name = "game_humans", joinColumns = #JoinColumn(name = "game_id"))
#MapKeyColumn(name = "human_id")
#Column(name = "isDead")
private Map<Human, Boolean> humans;
And here is my Human entity :
#Entity
#Table(name = "human")
public class Human implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
#Column(name = "name")
private String name;
#OneToOne
private Building building;
To get the list of all the humans stored in the DB, I use this DAO, which is working very well and gets also the Building entity :
public class HumanDAO implements DAO<Human> {
// ...
public List<Human> getAllHumans() {
TypedQuery<Human> query = em.createQuery("SELECT h FROM human h ORDER BY h.name", Human.class);
return query.getResultList();
}
The problem is when I try to do the same to get the list of all the games with the JPQL query SELECT g FROM game g, I get this error :
[EL Info]: 2013-11-25 13:40:27.761--ServerSession(1943119327)--EclipseLink, version: Eclipse Persistence Services - 2.5.0.v20130507-3faac2b
[EL Info]: connection: 2013-11-25 13:40:28.151--ServerSession(1943119327)--file:/Users/amine/Documents/workspace/ZombiesServer/target/classes/_ZombiesServer login successful
[WARNING]
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.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [SELECT g FROM game g].
[14, 18] The abstract schema type 'game' is unknown.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1585)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1605)
at com.amine.zombies.DAO.GameDAO.getAllGames(GameDAO.java:80)
at com.amine.zombies.application.Application.main(Application.java:21)
... 6 more
You should have
SELECT g FROM Game g//you have game
but you have game instead of Game.
The #Table annotation is used for DB.
If you need to change the name in your JPQL, use the #Entity annotation: #Entity(name="nameUsedInJPQL") => nameUsedInJPQL is used in your JPQL.
If you do not specify anything in your #Entity, that the case-sensitive Entity class name is used.
In my case I forgot to register it in persistence.xml.
I just had the very same situation but my JPQL query was correct ! It occured in Glassfish 4.1 (build 13) (with EclipseLink).
After a few googling and some code commenting, I found out that the root cause of "The abstract schema type 'MyEntity' is unknown" was some use of Java 8 lambda code inside the entity class.
It seems that any feature of Java 8 is not (yet) supported in the version of EclipseLink that comes with GF. More info, see the bug report on that.
Hope this helps.
class name should be there not the table name in your query
SELECT g FROM Game g
The name to be used for JPQL queries is defined as the simple name of the entity class - Game or Human in your case. It can be overridden by the name attribute of the #Entity annotation. #Table is a physical mapping annotation and does not influence the entity name in the query.
It does work with human because the query string is not case-sensitive.
We got the problem due to an update of org.eclipse.persistence.eclipselink library from 2.4.0 to 2.5.1. After updating to 2.6.2 it works again.
If you are calling the persistence.xml in a bundle, then org.eclipse.persistence.jpa must be started before your bundle (or bundles). If not, you will get the same exception. You will also see that the tables have not been made in your database. It is therefore a good idea to always add org.eclipse.persistence as an imported package in your manifest.
In my case no answer help me. My JPA project was using Java 14 with EclipseLink 3.0.0 as a provider and seems as EclipseLink doesn´t support new Java versions. Switching back to Java 1.7 did the trick.

Categories

Resources