Tag: jpa

为什么JPA有一个@Transient注解?

Java有transient关键字。 为什么JPA有@Transient而不是简单地使用已经存在的java关键字?

在JPA中为列设置默认值

是否有可能为JPA中的列设置默认值,以及如何使用注释完成该操作?

hibernate和没有PK

是否有可能创build一个表(从JPA注释的Hibernate @ @Entity )不包含主键/ ID? 我知道这不是一个好主意, 一个表应该有一个主键。

JPAhibernate一对一的关系

我有一对一的关系,但是hibernatetool在生成模式时抱怨。 这是一个显示问题的例子: @Entity public class Person { @Id public int id; @OneToOne public OtherInfo otherInfo; rest of attributes … } Person与OtherInfo有一对一的关系: @Entity public class OtherInfo { @Id @OneToOne(mappedBy="otherInfo") public Person person; rest of attributes … } 人是拥有OtherInfo的一面。 OtherInfo是所有者,所以人使用mappedBy来指定Person中的属性名称“otherInfo”。 使用hibernatetool生成数据库模式时,出现以下错误: org.hibernate.MappingException: Could not determine type for: Person, at table: OtherInfo, for columns: [org.hibernate.mapping.Column(person)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:292) at […]

JPA:如何具有相同实体types的一对多关系

有一个实体类“A”。 A类可能有同一types“A”的孩子。 另外“A”应该是它的父母,如果它是一个孩子。 这可能吗? 如果是的话我应该如何映射实体类中的关系? [“A”有一个id列。]

JPA / Hibernate原生查询不识别参数

我正在使用Hibernate / JPA来执行原生的PostGIS查询。 这些查询的问题是他们需要的参数不是经典的X ='value'forms。 例如,以下行会崩溃 String queryString = "select * from Cell c where ST_DWithin(c.shape, SetSRID(ST_GeomFromEWKT('POINT(:lon :lat)'),4326), 0.1)"; Query query = Cell.em().createNativeQuery(queryString, Cell.class); query.setParameter("lon", longitude); query.setParameter("lat", latitude); play.exceptions.JavaExecutionException: org.hibernate.QueryParameterException: could not locate named parameter [lon] at play.mvc.ActionInvoker.invoke(ActionInvoker.java:259) at Invocation.HTTP Request(Play!) Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: could not locate named parameter [lon] at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:358) 以下查询适用于: String […]

Spring-Data-JPA注释的setMaxResults?

我正在尝试将Spring-Data-JPA合并到我的项目中。 有一件事让我困惑的是如何通过注释来实现setMaxResults(n)? 例如,我的代码: public interface UserRepository extends CrudRepository<User , Long> { @Query(value="From User u where u.otherObj = ?1 ") public User findByOhterObj(OtherObj otherObj); } 我只需要从其他对象中返回one (and only one)用户,但我找不到注释maxResults的方法…有人可以给我一个提示吗? (mysql抱怨: com.mysql.jdbc.JDBC4PreparedStatement@5add5415: select user0_.id as id100_, user0_.created as created100_ from User user0_ where user0_.id=2 limit ** NOT SPECIFIED ** WARN util.JDBCExceptionReporter – SQL Error: 0, SQLState: 07001 […]

Spring Boot – 无法确定数据库types为NONE的embedded式数据库驱动程序类

这是尝试运行我的Web应用程序时引发的错误: [INFO] WARNING: Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public […]

持久性单元作为RESOURCE_LOCAL或JTA?

我有如下查询: 这两者有什么不同? 这两个都支持所有的数据库? JPA TransactionManager和JTA TransactionManager是不同的?

如何从我的控制器中加载Hibernate / JPA中的延迟获取项目

我有一个Person类: @Entity public class Person { @Id @GeneratedValue private Long id; @ManyToMany(fetch = FetchType.LAZY) private List<Role> roles; // etc } 有一个懒惰的多对多的关系。 在我的控制器中,我有 @Controller @RequestMapping("/person") public class PersonController { @Autowired PersonRepository personRepository; @RequestMapping("/get") public @ResponseBody Person getPerson() { Person person = personRepository.findOne(1L); return person; } } 而PersonRepository就是这个代码,按照这个指南写的 public interface PersonRepository extends JpaRepository<Person, Long> { } 但是,在这个控制器中我实际上需要懒惰数据。 […]