SpringbootJPA实体类添加@Transient Hibernate
在实体类与数据库表建⽴映射关系时添加@Table注解, 当表中不存在实体类中的某个属性的时候, 就需要⽤到 @Transient 注解⽤法: 添加在需要忽略的实体类属性上
@Transient
private String columeName;
实体类
import com.fasterxml.jackson.annotation.JsonIgnore;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.Data;
import javax.persistence.*;
@lombok.Data
@Entity
public class UserMonitorStationMapping {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private Integer monitorStationId;
@Transient
private String shortName; // TODO 数据库表中⽆此字段
@ManyToOne
@JsonIgnore
private User user;
}
数据库表结构
ption.SQLGrammarException: could not extract ResultSet
at ption.vert(SQLExceptionTypeDelegate.java:82)
springboot结构at ption.vert(StandardSQLExceptionConverter
.java:49)at ine.jdbc.vert(SqlExceptionHelper.java:124)
at ine.jdbc.vert(SqlExceptionHelper.java:109)
at ine.jdbc.act(ResultSetReturnImpl.java:88)
at org.hibernate.ResultSet(Loader.java:2062)
at org.hibernate.uteQueryStatement(Loader.java:1859)
at org.hibernate.uteQueryStatement(Loader.java:1838)
at org.hibernate.loader.Loader.doQuery(Loader.java:906)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:348)
at org.hibernate.loader.Loader.doList(Loader.java:2550)
at org.hibernate.loader.Loader.doList(Loader.java:2536)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2366)
at org.hibernate.loader.Loader.list(Loader.java:2361)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:357)
at ine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:198)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1230)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
at com.bbs.dao.BaseDao.list(BaseDao.java:82)
at com.bbs.dao.BaseDao.list(BaseDao.java:92)
at com.bbs.service.impl.OrderServiceImpl.selectOrdersByOne(OrderServiceImpl.java:35)
at com.bbs.service.impl.OrderServiceImpl
解决⽅法
在实体类上添加@Transient注解
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论