java - 如何在hibernate中使用类org.hibernate.annotations.Table的@Table注解
问题描述
我的班级名称是
批处理作业
我的表名是
批处理作业
我正在使用 org.hibernate.annotations.Table 类的 @Table 而不是 javax.persistence
我的 BatchJob 类代码是
import javax.persistence.Entity;
import org.hibernate.annotations.Table;
@Entity
@Table(appliesTo="batch_jobs")
public class BatchJob {
我收到错误
org.hibernate.AnnotationException:@org.hibernate.annotations.Table 引用了一个未知的表:batch_jobs
当我将@Entity 表示法的类更改为 org.hibernate.annotations
import org.hibernate.annotations.Entity;
import org.hibernate.annotations.Table;
@Entity
@Table(appliesTo="batch_jobs")
public class BatchJob {
我收到错误
org.hibernate.hql.internal.ast.QuerySyntaxException:BatchJob 未映射 [来自 BatchJob]
我的查询
allBatchJobs=session.createQuery("From BatchJob").list();
我的 hibernate.cfg.xml 映射
<mapping class="com.company.bmdashboard.beans.BatchJob"></mapping>
当我将我的类名更改为 batch_jobs 时,代码工作正常,但我想使用名称 BatchJob 并且我不想使用 javax.persistence 类。
请指导我。提前致谢
解决方案
@org.hibernate.annotations.Table
使用来自javax.persistence.Table;
和/或来自的值javax.persistence.SecondaryTables;
。例如:
@Table(name = "batch_jobs")
@SecondaryTables({
@SecondaryTable(name="batch")
})
@Entity
@org.hibernate.annotations.Table(inverse = true, appliesTo = "batch")
public class BatchJob {
所以,@org.hibernate.annotations.Table
不等于javax.persistence.Table;
,这是不同目的的不同注解。
推荐阅读
- oracle-apex - Oracle APEX - 可重用页面?
- firebase - 如何更新在查询中找到的文档?
- android - 会话“应用程序”:在 android studio 中启动活动时出错
- javascript - 为什么 JavaScript 没有命名参数?
- machine-learning - 如何选择特征进行聚类?
- dart - 每次按键时在 dart TextField 中执行方法
- ios - 如何使用 Swift 创建底部表单样式模型视图控制器?
- python - Python,websocket在某些机器上自动关闭
- machine-learning - 神经网络的小词汇量可以吗?
- python - Looking for an elegant way for looping simultaneously over two list with different lengths