MovieEntity:
@Entity(name="MovieEntity")
@Table(name="Movie")
public class MovieEntity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="Id")
private long id;
@Column(name="IsDeleted")
private boolean isDeleted;
@Column(name="ModifiedDate")
private Date modifiedDate;
@OneToOne(optional = false)
@JoinColumn(name="MovieTypeId")
private MovieTypeEntity movieTypeEntity;
@OneToOne(mappedBy="movieEntity",optional = false)
private MovieVersionEntity movieVersionEntity;
getter and setter methods
}
MovieTypeEntity:
@Entity(name = "MovieTypeEntity")
@Table(name = "MovieType")
public class MovieTypeEntity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="MovieTypeId")
private int movieTypeId;
@Column(name="Type")
private String type;
@Column(name="IsDeleted")
private boolean isDeleted;
@OneToOne(mappedBy="movieTypeEntity",optional = false)
private MovieEntity movieEntity;
getter and setters.
}
MovieVersionEntity:
@Entity(name = "MovieVersionEntity")
@Table(name="MovieVersion")
//@EntityListeners(AuditingEntityListener.class)
public class MovieVersionEntity {
@Id()
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="MovieId")
private long movieId;
@NotBlank
@Column(name="MovieName")
private String movieName;
@NotBlank
@Column(name="DirectorName")
private String directorName;
@NotBlank
@Column(name="Description")
private String description;
@Column(name="StopDate")
@Temporal(TemporalType.TIMESTAMP)
private Date endDate;
@Column(name="DoneWatching")
private boolean doneWatching;
@Column(name="WatchDate")
@Temporal(TemporalType.TIMESTAMP)
//@CreatedDate
private Date watchDate;
@Column(name="ModifiedDate")
@Temporal(TemporalType.TIMESTAMP)
//@LastModifiedDate
private Date modifiedDate;
@OneToOne(optional = false)
@JoinColumn(name="Id")
private MovieEntity movieEntity;
getter and setters
}
MovieRepository:
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.entertainment.entertainment.entity.MovieEntity;
@Repository
@Transactional(readOnly=true)
public interface MovieRepository extends org.springframework.data.repository.Repository<MovieEntity, Long> {
@Modifying
MovieEntity save(MovieEntity movieEntity);
@Query("Select me.id from MovieEntity me inner join fetch me.movieVersionEntity as mve where mve.name = :name " +
"and me.isDeleted = 0 and mve.endDate is null")
long doesMovieExistWithName(@Param("name") String name);
@Query("Select me from MovieEntity me inner join fetch me.movieVersionEntity as mve where me.id = :id and " +
"me.isDeleted=0 and mve.endDate is null")
Optional<MovieEntity> getMovie(@Param("id") long id);
@Query("Select me from MovieEntity me inner join fetch me.movieVersionEntity as mve where me.isDeleted=0 and mve.endDate is null")
List<MovieEntity> getMovies();
}
MovieTypeRepository:
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.entertainment.entertainment.entity.MovieTypeEntity;
@Repository
@Transactional(readOnly=true)
public interface MovieTypeRepository extends org.springframework.data.repository.Repository<MovieTypeEntity, Integer> {
@Modifying
MovieTypeEntity save(MovieTypeEntity movieTypeEntity);
}
MovieVersionRepository:
package com.entertainment.entertainment.repository;
import com.entertainment.entertainment.entity.MovieVersionEntity;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
@Transactional(readOnly = true)
public interface MovieVersionRepository extends org.springframework.data.repository.Repository<MovieVersionEntity,Long> {
}
错误:
Caused by: org.hibernate.QueryException: could not resolve property: name of: com.entertainment.entertainment.entity.MovieVersionEntity [Select me.id from com.entertainment.entertainment.entity.MovieEntity me inner join fetch me.movieVersionEntity as mve where mve.name = :name and me.isDeleted = 0 and mve.endDate is null]
at org.hibernate.QueryException.generateQueryException(QueryException.java:120) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:302) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:240) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1894) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
... 62 common frames omitted
Caused by: org.hibernate.QueryException: could not resolve property: name of: com.entertainment.entertainment.entity.MovieVersionEntity
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:62) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:56) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1805) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.tree.FromElementType.getPropertyType(FromElementType.java:393) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.tree.FromElement.getPropertyType(FromElement.java:505) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.tree.DotNode.getDataType(DotNode.java:660) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.tree.DotNode.prepareLhs(DotNode.java:264) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.tree.DotNode.resolve(DotNode.java:204) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:109) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:104) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:942) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1283) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4696) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4166) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2131) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2056) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2056) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:810) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:605) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:309) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:257) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
... 70 common frames omitted
我不确定导致此错误的是什么我尝试调试并再次检查代码但没有运气?我似乎已经正确定义了Entity类中的所有属性。知道这里有什么问题吗?
答案 0 :(得分:1)
在查询items
where子句有doesMovieExistWithName
的情况下。但是,mve.name = :name "
中没有定义名为name
的属性。我认为它应该是MovieVersionEntity