求解答疑惑关联映射问题,捉急,在线等。
小白,求解答疑惑
仿照系统表TSRoleUser, 关联映射VoteEntity和TSUser实体。测试后成功插入。仿制的VoterEntity大致具体如下。
@Entity
@Table(name = "tabvoter")
public class VoterEntity extends IdEntity implements java.io.Serializable {
private VoteEntity VoteEntity;
private TSUser TSUser;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "varvoteid")
public VoteEntity getVoteEntity() {
return this.VoteEntity;
}
public void setVoteEntity(VoteEntity VoteEntity) {
this.VoteEntity = VoteEntity;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "varuserid")
public TSUser getTSUser() {
return this.TSUser;
}
public void setTSUser(TSUser TSUser) {
this.TSUser = TSUser;
}
但查询实体时
List<VoterEntity> VoterEntity = voteService.findByProperty(VoterEntity.class, "VoteEntity.id", vote.getId());
其中
findByProperty(VoterEntity.class, "VoteEntity.id", vote.getId())里的VoteEntity.id属性找不到,报错。
而如下查询
List<VoterEntity> VoterEntity = voteService.findByProperty(VoterEntity.class, "TSUser.id", vote.getId());里的TSUser.id正确。
是不是配置映射时,还是其中哪一步少配了什么,请好心人指点,都需配哪些东西。
有关的实体 都贴来看看 GIN 发表于 2013-11-23 16:59 static/image/common/back.gif
有关的实体 都贴来看看
//VoterEntity.java
package com.lingdong.entity.xml;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.jeecgframework.core.common.entity.IdEntity;
import com.lingdong.system.pojo.base.TSUser;
import com.lingdong.entity.xml.VoteEntity;
/**
* Voterentity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "tabvoter")
public class VoterEntity extends IdEntity implements java.io.Serializable {
private VoteEntity VoteEntity;
private TSUser TSUser;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "varvoteid")
public VoteEntity getVoteEntity() {
return this.VoteEntity;
}
public void setVoteEntity(VoteEntity VoteEntity) {
this.VoteEntity = VoteEntity;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "varuserid")
public TSUser getTSUser() {
return this.TSUser;
}
public void setTSUser(TSUser TSUser) {
this.TSUser = TSUser;
}
}
GIN 发表于 2013-11-23 16:59 static/image/common/back.gif
有关的实体 都贴来看看
//VoteEntity.java
package com.lingdong.entity.xml;
import java.math.BigDecimal;
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.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.SequenceGenerator;
/**
* @Title: Entity
* @Description: 投票功能
* @author zhangdaihao
* @date 2013-11-21 18:19:32
* @version V1.0
*
*/
@Entity
@Table(name = "tabvote", schema = "")
@SuppressWarnings("serial")
public class VoteEntity implements java.io.Serializable {
/**id*/
private java.lang.String id;
/**varvotename*/
private java.lang.String varvotename;
/**datecreatedate*/
private java.util.Date datecreatedate;
/**datedeadline*/
private java.util.Date datedeadline;
/**varvotedesc*/
private java.lang.String varvotedesc;
/**varisopen*/
private java.lang.String varisopen;
/**varpublisher*/
private java.lang.String varpublisher;
/**varissingle*/
private java.lang.String varissingle;
/**varattachment*/
private java.lang.String varattachment;
/**
*方法: 取得java.lang.String
*@return: java.lang.Stringid
*/
@Id
@GeneratedValue(generator = "paymentableGenerator")
@GenericGenerator(name = "paymentableGenerator", strategy = "uuid")
@Column(name ="ID",nullable=false,length=32)
public java.lang.String getId(){
return this.id;
}
/**
*方法: 设置java.lang.String
*@param: java.lang.Stringid
*/
public void setId(java.lang.String id){
this.id = id;
}
/**
*方法: 取得java.lang.String
*@return: java.lang.Stringvarvotename
*/
@Column(name ="VARVOTENAME",nullable=false,length=50)
public java.lang.String getVarvotename(){
return this.varvotename;
}
/**
*方法: 设置java.lang.String
*@param: java.lang.Stringvarvotename
*/
public void setVarvotename(java.lang.String varvotename){
this.varvotename = varvotename;
}
/**
*方法: 取得java.util.Date
*@return: java.util.Datedatecreatedate
*/
@Column(name ="DATECREATEDATE",nullable=false)
public java.util.Date getDatecreatedate(){
return this.datecreatedate;
}
/**
*方法: 设置java.util.Date
*@param: java.util.Datedatecreatedate
*/
public void setDatecreatedate(java.util.Date datecreatedate){
this.datecreatedate = datecreatedate;
}
/**
*方法: 取得java.util.Date
*@return: java.util.Datedatedeadline
*/
@Column(name ="DATEDEADLINE",nullable=true)
public java.util.Date getDatedeadline(){
return this.datedeadline;
}
/**
*方法: 设置java.util.Date
*@param: java.util.Datedatedeadline
*/
public void setDatedeadline(java.util.Date datedeadline){
this.datedeadline = datedeadline;
}
/**
*方法: 取得java.lang.String
*@return: java.lang.Stringvarvotedesc
*/
@Column(name ="VARVOTEDESC",nullable=true,length=500)
public java.lang.String getVarvotedesc(){
return this.varvotedesc;
}
/**
*方法: 设置java.lang.String
*@param: java.lang.Stringvarvotedesc
*/
public void setVarvotedesc(java.lang.String varvotedesc){
this.varvotedesc = varvotedesc;
}
/**
*方法: 取得java.lang.String
*@return: java.lang.Stringvarisopen
*/
@Column(name ="VARISOPEN",nullable=true,length=1)
public java.lang.String getVarisopen(){
return this.varisopen;
}
/**
*方法: 设置java.lang.String
*@param: java.lang.Stringvarisopen
*/
public void setVarisopen(java.lang.String varisopen){
this.varisopen = varisopen;
}
/**
*方法: 取得java.lang.String
*@return: java.lang.Stringvarpublisher
*/
@Column(name ="VARPUBLISHER",nullable=false,length=32)
public java.lang.String getVarpublisher(){
return this.varpublisher;
}
/**
*方法: 设置java.lang.String
*@param: java.lang.Stringvarpublisher
*/
public void setVarpublisher(java.lang.String varpublisher){
this.varpublisher = varpublisher;
}
/**
*方法: 取得java.lang.String
*@return: java.lang.Stringvarissingle
*/
@Column(name ="VARISSINGLE",nullable=true,length=1)
public java.lang.String getVarissingle(){
return this.varissingle;
}
/**
*方法: 设置java.lang.String
*@param: java.lang.Stringvarissingle
*/
public void setVarissingle(java.lang.String varissingle){
this.varissingle = varissingle;
}
/**
*方法: 取得java.lang.String
*@return: java.lang.Stringvarattachment
*/
@Column(name ="VARATTACHMENT",nullable=true,length=200)
public java.lang.String getVarattachment(){
return this.varattachment;
}
/**
*方法: 设置java.lang.String
*@param: java.lang.Stringvarattachment
*/
public void setVarattachment(java.lang.String varattachment){
this.varattachment = varattachment;
}
} GIN 发表于 2013-11-23 16:59 static/image/common/back.gif
有关的实体 都贴来看看
//TSUser.java
package com.lingdong.system.pojo.base;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
/**
* 系统用户表
*
* @author jeecg
*/
@Entity
@Table(name = "t_s_user")
@PrimaryKeyJoinColumn(name = "id")
public class TSUser extends TSBaseUser implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private String signatureFile;// 签名文件
private String mobilePhone;// 手机
private String officePhone;// 办公电话
private String email;// 邮箱
@Column(name = "signatureFile", length = 100)
public String getSignatureFile() {
return this.signatureFile;
}
public void setSignatureFile(String signatureFile) {
this.signatureFile = signatureFile;
}
@Column(name = "mobilePhone", length = 30)
public String getMobilePhone() {
return this.mobilePhone;
}
public void setMobilePhone(String mobilePhone) {
this.mobilePhone = mobilePhone;
}
@Column(name = "officePhone", length = 20)
public String getOfficePhone() {
return this.officePhone;
}
public void setOfficePhone(String officePhone) {
this.officePhone = officePhone;
}
@Column(name = "email", length = 50)
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
}
//TSBaseUser.java
package com.lingdong.system.pojo.base;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.jeecgframework.core.common.entity.IdEntity;
/**
* 系统用户父类表
*
*/
@Entity
@Table(name = "t_s_base_user")
@Inheritance(strategy = InheritanceType.JOINED)
public class TSBaseUser extends IdEntity implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private String userName;// 用户名
private String realName;// 真实姓名
private String browser;// 用户使用浏览器类型
private String userKey;// 用户验证唯一标示
private String password;//用户密码
private Short activitiSync;//是否同步工作流引擎
private Short status;// 状态1:在线,2:离线,0:禁用
private byte[] signature;// 签名文件
private TSDepart TSDepart = new TSDepart();// 部门
@Column(name = "signature")
public byte[] getSignature() {
return signature;
}
public void setSignature(byte[] signature) {
this.signature = signature;
}
@Column(name = "browser", length = 20)
public String getBrowser() {
return browser;
}
public void setBrowser(String browser) {
this.browser = browser;
}
@Column(name = "userkey", length = 200)
public String getUserKey() {
return userKey;
}
public void setUserKey(String userKey) {
this.userKey = userKey;
}
@Column(name = "status")
public Short getStatus() {
return this.status;
}
public void setStatus(Short status) {
this.status = status;
}
public Short getActivitiSync() {
return activitiSync;
}
@Column(name = "activitisync")
public void setActivitiSync(Short activitiSync) {
this.activitiSync = activitiSync;
}
@Column(name = "password", length = 10)
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "departid")
public TSDepart getTSDepart() {
return this.TSDepart;
}
public void setTSDepart(TSDepart TSDepart) {
this.TSDepart = TSDepart;
}
@Column(name = "username", nullable = false, length = 10)
public String getUserName() {
return this.userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Column(name = "realname", length = 50)
public String getRealName() {
return this.realName;
}
public void setRealName(String realName) {
this.realName = realName;
}
}
//IdEntity.java
package org.jeecgframework.core.common.entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import org.hibernate.annotations.GenericGenerator;
@MappedSuperclass
public abstract class IdEntity {
private String id;
@Id
@GeneratedValue(generator = "hibernate-uuid")
@GenericGenerator(name = "hibernate-uuid", strategy = "uuid")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
} 感觉不是实体类的原因,错误藐视可以多点吗? 本帖最后由 jasonchen 于 2013-11-23 22:16 编辑
jueyue 发表于 2013-11-23 21:52 static/image/common/back.gif
感觉不是实体类的原因,错误藐视可以多点吗?
此句:
//VoteController.java
List<VoterEntity> VoterEntity = voteService.findByProperty(VoterEntity.class, "VoteEntity.id", vote.getId());
产生错误:
错误异常: QueryException错误描述:could not resolve property: VoteEntity of: com.lingdong.entity.xml.VoterEntity错误信息:org.hibernate.QueryException: could not resolve property: VoteEntity of: com.lingdong.entity.xml.VoterEntity at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:83) at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:77) at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1832) at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:61) at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1807) at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:522) at org.hibernate.loader.criteria.CriteriaQueryTranslator.findColumns(CriteriaQueryTranslator.java:537) at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:66) at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:419) at org.hibernate.loader.criteria.CriteriaJoinWalker.(CriteriaJoinWalker.java:123) at org.hibernate.loader.criteria.CriteriaJoinWalker.(CriteriaJoinWalker.java:92) at org.hibernate.loader.criteria.CriteriaLoader.(CriteriaLoader.java:93) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1516) at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374) at org.jeecgframework.core.common.dao.impl.GenericBaseCommonDao.findByProperty(GenericBaseCommonDao.java:151) at org.jeecgframework.core.common.service.impl.CommonServiceImpl.findByProperty(CommonServiceImpl.java:133) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy43.findByProperty(Unknown Source) at com.lingdong.controller.VoteController.idandname(VoteController.java:204) at com.lingdong.controller.VoteController.addorupdate(VoteController.java:199) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) at javax.servlet.http.HttpServlet.service(HttpServlet.java:690) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:140) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:119) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619)
页:
[1]