gpt4 book ai didi

java - 线程 "main"org.hibernate.AnnotationException : @org. hibernate.annotations.Table 中的异常引用未知表:ProductForPractice

转载 作者:行者123 更新时间:2023-12-02 03:24:18 24 4
gpt4 key购买 nike

我正在尝试开发 Hibernate 4.1.4 版本功能。当我尝试运行代码时,我正在使用 hsqldb 2.3.3,它给了我未知的表引用。

这是我的表格脚本:

CREATE TABLE ProductForPractice (productId INTEGER,prodName char(25),price DECIMAL(5,2),PRIMARY KEY(productId))

实体类

@Entity

@Table(appliesTo="ProductForPractice")
public class Product {


@Id
@Column

private int productId;



@Column(name="prodName")
private String prodName;
@Column
private double price;
@Version
private long version;
//getter and setters

这是我的配置文件

config.setProperty("hbm2ddl.auto", "create");
config.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
config.setProperty("hibernate.connection.url", "jdbc:hsqldb:hsql://localhost/");
config.setProperty("hibernate.connection.username", "SA");
config.setProperty("hibernate.connection.password", "");
config.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
config.addAnnotatedClass(Product.class);

config.setProperty("hibernate.archive.autodetection", "class,hbm");

ServiceRegistry serivce=new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
SessionFactory factory=config.buildSessionFactory(serivce);

这是我的完整堆栈跟踪:

Exception in thread "main" org.hibernate.AnnotationException: @org.hibernate.annotations.Table references an unknown table: ProductForPractice
at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:933)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:713)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3435)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3389)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1341)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1731)
at Hibernate.configuration.Service.saveProduct(Service.java:28)
at main.Main1.main(Main1.java:15)

最佳答案

您的表注释可能属于 org.hibernate.annotations.Table 类,它只是将信息添加到您应该使用的注释 javax.persistence.Table 中:

@javax.persistence.Table(name="ProductForPractice")
public class Product {

关于java - 线程 "main"org.hibernate.AnnotationException : @org. hibernate.annotations.Table 中的异常引用未知表:ProductForPractice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39185108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com