我有一个像这样的实体类:
@Entity
@Table (name="CART_ITEM")
public class CartItem {
@Id
@GeneratedValue (strategy=GenerationType.AUTO)
@Column (name="ID")
private int id;
@Column (name="AMOUNT")
private int amount;
...
它适用于数据库。但是,当我删除列AMOUNT并删除上面的相应字段(使用getter和setter)并重新启动应用程序时,我得到了这个:
Exception sending context initialized event to listener instance of class com.retailstore.AppContextListener
javax.persistence.PersistenceException: [PersistenceUnit: manager] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at com.retailstore.AppContextListener.createEntityManagerFactory(AppContextListener.java:76)
at com.retailstore.AppContextListener.contextInitialized(AppContextListener.java:66)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [AMOUNT] in table [CART_ITEM]
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:85)
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:50)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:91)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:473)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
... 14 more
我之前已多次这样做,从未遇到过这个问题。有人有什么建议吗?
更新:
我认为问题已经解决了。还有WEB-INF / classes下的旧类。
答案 0 :(得分:0)
我认识到WEB-INF / classes包含与此实体冲突的旧类。我删除了那些并且应用程序有效。