HSQLDB 2.2 skipping certain entities and not creat

2019-09-09 17:47发布

问题:

I am working with Hibernate 3.5.5 and HSQLDB 2.2.9. I use JPA semantics to define Entities and have around 10 entities.

For some unknown reason, the HSQLDB doesn't seem to be picking three entities as I don't find the corresponding tables in the HSQLDB explorer and any reference to those tables result in SQL exception user lacks privilege or object not found: <TableName>.

All the three entities are in the same format as the other ones and as follows:

@Entity
@Table(name = "<TABLE_NAME>")
public class TableName
{
     // private members;

     // protected default constructor for the ORM

     @Id
     @Column(name = <PRIMARY_KEY>)
     // public getter for Primary Key member.

     @Column(name = <COLUMN_NAME>)
     // public getters for all other members;

     // protected setters
}

Did anyone face a similar issue where HSQLDB is skipping some entities?

At least, it is consistently skipping the same three entities and I am not able to figure out what is different in those from the rest. All these entities are generated using the JPA facet in Eclipse so there is no difference as such among these.

Edit 1:

My persistence.xml simply has this:

<persistence-unit name="fssPersistenceUnit" transaction-type="RESOURCE_LOCAL">
</persistence-unit>

and HSQLDB 2.0 used to pick all the entities annotated with @Entity, whereas HSQLDB 2.2.9 doesn't pick all and leaves three entities as mentioned earlier.

Edit 2: After enabling the logging of SQL statements, I see that the CREATE TABLE statements for these three tables are rolled back. I am not able to get any further information on what was wrong with these create table statements. Also, the CREATE TABLE statement is truncated when printed.

回答1:

The Hibernate dialect for HSQLDB was updated in Hibernate 3.6 and later. It is not known if 3.5.x works well with HSQLDB 2.2.x

In any case, you can use a file: database and add the hsqldb.sqllog=2 property to the database URL. This will produce a log of all the executed SQL statements. You can then check for the statements for the missing tables.

See the Guide:

http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html



回答2:

Well, I'm guessing you don't actually have this exact text in your code:

@Entity
@Table(name = "<TABLE_NAME>")
public class TableName

(with an actual <TABLE_NAME> string), but that you wrote that just as a generic/pseudo code example. (because if you'd actually use the string "<TABLE_NAME>" it would be an invalid string for hibernate and it won't create the schema).

Can you tell us the actual table and column names that you use on the entities which do not have their tables created by Hibernate? In some cases the underlying db (HSQLDB in your case) has some reserved words which it will not allow for table and/or names, and it might fail silently if that's the case (I've stumbled upon this with PostgreSQL and MySQL, where a Hibernate generated schema would work in MySQL but would silently fail to create certain tables in PostgreSQL because a certain table name was not "liked" by the latter).

The same can apply to field/column names.