我有一个抽象类Log.java和两个实现类,名为CreateLog.java和UpdateLog.java,这两个表有一些条目,我试图在抽象实体级别获取这些条目。
我的类是:
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author user
*/
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@XmlRootElement
public abstract class Log implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@Column(name = "id")
private Integer id;
@Column(name = "log_date")
@Temporal(TemporalType.TIMESTAMP)
private Date logDate;
}
package com.kommbox.types;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
@Entity
@Table(name = "create_logs")
@XmlRootElement
public class CreateLog extends Log
{
}
package com.kommbox.types;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
@Entity
@Table(name = "update_logs")
@XmlRootElement
public class UpdateLog extends Log
{
}
我想获取所有日志,因此查询是:
public void getAllLogs()
{
try
{
List<Log> allLogs = em.createQuery("select log from com.types.Log log").getResultList();
if (allLogs.size() > 0)
{
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
以上查询给出错误&#34; org.hibernate.exception.DataException:无法执行查询&#34;。
请仅建议JPQL查询。