我有疑问:我们假设我有两个类用户和人,人扩展用户。在用户中我有@Inheritance(strategy=InheritanceType.JOINED)
。有时我只想选择不包含子表信息的用户信息,
User.java(超类)
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name = "user_type")
@Table(name = "users")
public class User {.........}
Person.java
@Entity
public class Person extends User {......}
Company.java
@Entity
public class Company extends User {.............}
UserRepository.java
@Transactional
public interface UserRepository extends UserBaseRepository<User> {
//@Query(value="select u from User u where u.email=?1")
@Query(value="select u.id,u.email from User u where u.email=?1")
User getUser(String email);
@Query("select u from User u where u.email=?1")
User getUser2(String email);
@Query(value="select * from Users where email=:email",nativeQuery=true)
User getUser3(String email);
}
发生以下异常:
Hibernate: select user0_.id as col_0_0_, user0_.email as col_1_0_ from users user0_ where user0_.email=?
org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.Object[] to type netgloo.models.User for value '{1, 635@qq.com}';
nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.Long to type netgloo.models.User
答案 0 :(得分:1)
要仅选择您可以使用JPQL TYPE()
运算符的用户,请执行以下操作:
SELECT u FROM User u WHERE TYPE(u) := User