Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jpa - Hibernate changes @Table(name) to lowercase

I have a Table Per Class Inheritance in Hibernate.

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class A {
}

@Entity
@Table(name="B")
public class B extends A {
}

@Entity
@Table(name="C")
public class C extends A {
}

I'm just trying to validate the schema. I have already B and C tables in db.

I'm using <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/> but I think that specifying @Table(name) override the behavior of naming strategy!

Why hibernate convert the name specified in @Table to lowerCase and searching for b and c instead of B and C? how can avoid it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you are using JPA 2.0, the spec says:

It is possible to specify that all database identifiers in use for a persistence unit be treated as delimited identifiers by specifying the <delimited-identifiers/> element within the persistence-unit-defaults element of the object/relational xml mapping file. If the <delimited-identifiers/> element is specified, it cannot be overridden.

This setting should cause Hibernate to use the uppercase names of your tables, since that is how you have specified the names in your annotations.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...