在jbossforhibernate的文档中指出
ImprovedNamingStrategy.classToTableName(String className)
方法的classname参数应返回完全限定的类名。
https://docs.jboss.org/hibernate/orm/4.1/javadocs/org/hibernate/cfg/improvednamingstrategy.html#classtotablename(java.lang.string)
classtotablename类
公共字符串classtotablename(字符串类名称)
返回非限定类名,大小写混合转换为下划线
指定人:
接口namingstrategy中的classtotablename
参数:classname-完全限定类名
返回:表名
但是,当我调试从improvednamingstrategy类扩展的类中的相关行时,它会返回非限定类名,而不是完全限定的类名。
我在这里要做的是让完全限定的类名来搜索是否有任何自定义注解放在该类上,以决定在创建表时应该使用哪个前缀。
例如:;
@CustomAnnotation("PREF_")
@Entity
public class MyEntity{}
使用这个信息hibernate应该创建一个这样的查询;
CREATE TABLE PREF_MyEntity;
我翻遍了文件,但什么也没找到。
有更好的方法吗?或者有什么最佳实践吗?
==更新==
我都尝试过hibernate配置中的包扫描和注解类选项,以查看是否有任何区别,但是没有区别。
<property name="packagesToScan">
<list>
<value>com.test.model</value>
</list>
</property>
和
<property name="annotatedClasses">
<list>
<value>com.test.model.MyEntity</value>
</list>
</property>
暂无答案!
目前还没有任何答案,快来回答吧!