我有两个POJO,STOCK和STOCK_DETAILS(一对多关系)。我也有一个接口IAUDITLOG(具有两种方法)。我需要两个POJO都实现此接口,并想在这些方法中编写一些实现。但是,当我使用子类“
STOCKDETAILS”实现IAUDITLOG接口时,它将给出异常“您应具有setter属性”
股票分类:
@Entity
@Table(name = "stock")
public class Stock implements java.io.Serializable, IAuditLog
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer stockId;
@Column(name = "STOCK_CODE")
private String stockCode;
@Column(name = "STOCK_NAME")
private String stockName;
@OneToMany( fetch = FetchType.LAZY, mappedBy = "stock")
public Set<StockDetail> stockDetails = new HashSet<StockDetail>(0);
public Set<StockDetail> getStockDetails() {
return stockDetails;
}
public void setStockDetails(Set<StockDetail> stockDetails) {
this.stockDetails = stockDetails;
}
public Integer getStockId() {
return stockId;
}
public void setStockId(Integer stockId) {
this.stockId = stockId;
}
public String getStockCode() {
return stockCode;
}
public void setStockCode(String stockCode) {
this.stockCode = stockCode;
}
public String getStockName() {
return stockName;
}
public void setStockName(String stockName) {
this.stockName = stockName;
}
// overridded methods of IAUDITLOG interface
public int getLogId() {
return stockId;
}
public String getLogDetail() {
return "some implementaion";
}
}
库存明细类
@Entity
@Table(name = "StockDetail")
public class StockDetail implements Serializable, IAuditLog {
/**
*
*/
private static final long serialVersionUID = 1L;
private Integer recordId;
private Stock stock;
private Float priceOpen;
@Id
@GeneratedValue
@Column(name = "RECORD_ID", unique = true, nullable = false)
public Integer getRecordId() {
return this.recordId;
}
public void setRecordId(Integer recordId) {
this.recordId = recordId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "STOCK_ID", nullable = false)
public Stock getStock() {
return this.stock;
}
public void setStock(Stock stock) {
this.stock = stock;
}
@Column(name = "PRICE_OPEN", precision = 6)
public Float getPriceOpen() {
return this.priceOpen;
}
public void setPriceOpen(Float priceOpen) {
this.priceOpen = priceOpen;
}
//overriddded methods of IADUTILOG inteface
public int getLogId() {
// TODO Auto-generated method stub
return 0;
}
public String getLogDetail() {
// TODO Auto-generated method stub
return "some implementation";
}
}
IAUDITLOg界面:
public interface IAuditLog {
public int getLogId();
public String getLogDetail();
}
堆栈跟踪:
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:385)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1760)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1798)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSesshtml" target="_blank">ionFactory(LocalSessionFactoryBean.java:373)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 46 more
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:138)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:341)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:507)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:146)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
... 55 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
... 64 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property logDetail in class com.auditLog.common.StockDetail
at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:252)
at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:245)
at org.hibernate.mapping.Property.getSetter(Property.java:326)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:444)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:201)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:82)
... 69 more
Feb 26, 2014 10:17:08 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet dispatcher
org.hibernate.PropertyNotFoundException: Could not find a setter for property logDetail in class com.auditLog.common.StockDetail
at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:252)
at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:245)
at org.hibernate.mapping.Property.getSetter(Property.java:326)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:444)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:201)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:82)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:341)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:507)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:146)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
任何人都可以让我知道吗,这可能是什么问题???为什么我应该为那些实际上不属于该类,而是通过其他接口实现的属性创建getter和setter。仅供参考…当我通过父类“
STOCK”实现此接口时,此方法工作正常
您应该使用@Transient注释覆盖的方法。
http://docs.oracle.com/javaee/5/api/javax/persistence/Transient.html
此批注指定属性或字段不是持久性的。它用于注释实体类,映射超类或可嵌入类的属性或字段。
Ps从Hibernate 3开始,默认情况下集合是惰性的,因此无需显式将其标记为惰性。
是否强制将我的外键实体从ClassA映射到ClassB中的主实体?
我认为错误并不在注释中,因为我更改了几次注释,仍然得到了相同的异常。
问题内容: 我正在尝试从Hibernate和Maven开始项目。 我有这样的例外: 这是我的项目结构的屏幕截图(hibernate.cfg.xml在src /中):http : //imageshack.us/photo/my- images/692/screenshotxba.jpg/ CrudsOps.java pom.xml 该异常的根源可能是什么? 问题答案: 正如@JBNizet所说,您
问题内容: 我有一堂课,看起来像下面这样: 我的hibernate映射文件按如下所示映射属性: 我收到以下错误: 看来hibernate不喜欢我的大写字母。我该如何解决? 问题答案: 应该管用…
map 0%reduce 0%15/02/03 07:30:28信息MapReduce.job:任务Id:尝试_1422885720829_0097_M_000000_0,状态:失败错误:java.lang.RuntimeException:java.lang.ClassNotFoundException:Class org.cnognizant.pr2.troublemapper在org.apa
你好,我是hibernate的新成员,目前我正在尝试做一些实践中的事情。但有一些错误。 我尝试在我的项目中使用hibernate。我阅读了教程,并开始将Hibernate集成到我的java maven项目中。所以首先我添加了下一个依赖项: 下一步是将hibernate.cfg.xml文件添加到src/main/resources目录中。此文件如下所示: 我还创建了类,它类似于: 当我尝试为方法创建