Tag: jpa

org.hibernate.MappingException:无法确定types:java.util.Set

虽然这个问题问了很多次,我已经使用了所有的build议,但我仍然得到这个错误。 User.java是 @Entity @Table(name = "USER") public class User implements UserDetails, Serializable { private static final long serialVersionUID = 2L; @Id @Column(name = "USER_ID") @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @Column(name = "USERNAME") private String username; @Column(name = "PASSWORD") private String password; @Column(name = "NAME") private String name; @Column(name = "EMAIL") private String email; @Column(name […]

JPA支持Java 8新的date和时间API

我为我的新项目使用Java 8。 我试图在java 8中使用新的date和时间api,但是我不知道JPA 2.1完全支持这个新的date和时间API或不。 请分享您的经验/意见在JPA的支持新的date和时间API在Java 8。 我可以安全地使用JPA 2.1在Java 8中使用新的date和时间api吗? 更新: 我正在使用Hibernate(4.3.5.Final)作为JPA实现。

JPA vs Spring JdbcTemplate

对于一个新的项目来说,JPA总是处理关系数据的推荐工具,或者Spring JdbcTemplate是一个更好的select吗? 您的回复中需要考虑的一些因素: 新的数据库模式vs预先存在的模式和表 开发人员的专业水平 易于与数据caching层集成 性能 还有其他相关因素需要考虑?

persistence.xml不同的事务types属性

在persistence.xml JPAconfiguration文件中,你可以有一行: <persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type="JTA"> 或有时: <persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type=”RESOURCE_LOCAL”> 我的问题是: transaction-type="JTA"和transaction-type=”RESOURCE_LOCAL”什么区别? 我还注意到一些事务types丢失的persistence.xml文件。 这是对的吗?

澄清术语:“保湿”实体:从数据库获取属性

在实体的ORM /惰性加载的情况下,我对“水合”一词的理解如下: “保湿”描述了填充使用延迟加载获取的实体的一些或全部先前未填充的属性的过程。 例如:class Author从数据库加载: @Entity class Author { @Id long id; List<Book> books; } 最初, bookscollections不填充。 我的理解是,从数据库加载books集合的过程被称为“保湿”集合。 这个定义是否正确,是常用的术语? 在这个过程中还有另一个更常见的术语吗?

JPA:如何将一个string持久化到数据库字段中,键入MYSQL Text

要求是用户可以写一篇文章,因此我select了在MySQL数据库内的content字段中inputText 。 如何将Java String转换为MySQL Text 在这里,你去Jim Tough @Entity public class Article implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private Long userId; private String title; private String content; private Integer vote; //Constructors, setters, getters, equals and hashcode } 在我的MYSQL数据库中, content是Texttypes的。 我希望能有这样的java.sql.Text ,因为java.sql.Blob是一个实际的types,但不幸的是,这并不存在

从JPA / EJB3持久性上下文中分离一个实体

什么是分离通过EntityManager获取的特定JPA实体Bean最简单的方法。 或者,我可以有一个查询返回分离的对象在第一个地方,所以他们将本质上作为“只读”? 我想这样做的原因是因为我想修改bean中的数据 – 只在我的应用程序中,但没有永久保存到数据库。 在我的程序中,我最终不得不在EntityManager上调用flush(),这会将附加实体的所有更改保存到解除数据库,但是我想排除特定的对象。

事务标记为仅回滚:如何find原因

我在使用@Transactional方法提交事务时遇到问题: methodA() { methodB() } @Transactional methodB() { … em.persist(); … em.flush(); log("OK"); } 当我从methodA()调用methodB()时,方法成功通过,我可以在日志中看到“OK”。 但是,然后我得到 Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:521) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) […]

spring – 是否有可能在同一个应用程序中使用多个事务pipe理器?

我是Spring的新手,我想知道是否可以在同一个应用程序中使用众多的事务pipe理器? 我有两个数据访问层 – 一个用于两个数据库。 我想知道,你如何去使用一个事务pipe理器的一层和不同的事务pipe理器的另一层。 我不需要在两个数据库之间执行事务。 但我确实需要单独对每个数据库执行事务。 我已经创build了一个图像来帮助概述我的问题: 这是我的应用程序上下文configuration: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:component-scan base-package="cheetah.repositories" /> <tx:annotation-driven /> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <property name="persistenceUnitName" value="accounts" /> </bean> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> </beans> 以下是使用此configuration的示例: @Repository public class JpaAccountRepository implements AccountRepository { @PersistenceContext(unitName = […]

Spring Data JPA通过embedded对象属性来查找

我想编写一个Spring Data JPA存储库接口方法签名,它使我能够在该实体中find具有embedded对象属性的实体。 有谁知道这是可能的,如果是的话,怎么样? 这是我的代码: @Entity @Table(name = "BOOK_UPDATE_QUEUE", indexes = { uniqueConstraints = @UniqueConstraint(columnNames = { "bookId", "region" }, name = "UK01_BOOK_UPDATE_QUEUE")) public class QueuedBook implements Serializable { @Embedded @NotNull private BookId bookId; … } @Embeddable public class BookId implements Serializable { @NotNull @Size(min=1, max=40) private String bookId; @NotNull @Enumerated(EnumType.STRING) private Region region; … […]