Tag: hibernate

我如何使用MS Access的hibernate?

我想用MS Access的hibernate。 我应该使用哪种方言,并且可以给我一个带MS Access的示例hibernateconfiguration文件?

简单的hibernate查询返回非常缓慢

我有以下的hibernate查询: Query query = session.createQuery("from MyHibernateClass"); List<MyHibernateClass> result = query.list();// executes in 7000ms logging在MySQL中执行的SQL我看到 select myhibernat0_.myFirstColumn as myfirstcolumn92_, myhibernat0_.mySecondColumn as mysecondcolumn92_, myhibernat0_.mythirdcolumn as mythirdcolumn92_, myhibernat0_.myFourthColumn as myfourthcolumn92_ from MyHibernateClass myhibernat0_ where (1=1); 当在MyHibernateClass数据库表中的3500行的小数据集中测量jvm中的java代码时,大约需要7000ms。 如果我另一方面使用直接jdbc,如下所示: Statement statement = session.connection().createStatement(); ResultSet rs = statement.executeQuery("select * from MyHibernateClass");// 7ms List<MyHibernateClass> result = convert(rs);// executes in 20ms 我看到相同的数据库进入数据库,但现在花费在jvm中的java代码的时间是7ms。 MyHibernateClass是一个简单的带有getter和setter的java […]

Spring事务和hibernate.current_session_context_class

我有一个使用Hibernate 4和Spring事务的Spring 3.2应用程序。 所有的方法工作得很好,我可以正确访问数据库来保存或检索实体。 然后,我介绍了一些multithreading,并且由于每个线程都访问数据库,我从Hibernate获得以下错误: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions 我从网上读到,我必须添加<prop key="hibernate.current_session_context_class">thread</prop>到我的Hibernateconfiguration,但现在每次我尝试访问数据库我得到: org.hibernate.HibernateException: saveOrUpdate is not valid without active transaction 然而,我的服务方法是用@Transactional注释的,并且在添加<prop key="hibernate.current_session_context_class">thread</prop>之前,所有工作都正常。 为什么没有交易,虽然方法用@Transactional注释? 我该如何解决这个问题? 这里是我的Hibernateconfiguration(包括会话上下文属性): <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <!– Hibernate session factory –> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" > <property name="dataSource" > […]

在模型类中使用javafx.beans属性

在模型类中使用JavaFX bean属性是否正确? 我想知道在模型类中使用属​​性是否能很好地将它们与视图组件绑定起来是一个好习惯。 我并不担心将来这些库的可用性,因为我的程序将在JRE8或更高版本上运行,但是在模型类中使用JavaFX库的性质使我感到怀疑,我特别担心当前和未来的不兼容问题,我想用Hibernate来坚持这些属性。 注意:我使用纯JavaFX环境,并且在我的应用程序中我永远不需要Swing兼容性。

如何在Spring Boot中使用Springpipe理的Hibernate拦截器?

在Spring Boot中是否可以集成Springpipe理的Hibernate拦截器( http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch14.html )? 我正在使用Spring Data JPA和Spring Data REST,并且需要Hibernate拦截器来处理实体上特定字段的更新。 使用标准的JPA事件不可能获得旧的值,因此我认为我需要使用Hibernate拦截器。

如何从连接表创build多个到多个Hibernate映射的附加属性?

我需要一个多对多的Hibernate映射,需要3个连接。 我试图find一个没有像LecturerCourse这样的中间实体的解决scheme。 在我的讲师和课程表之间,我的数据库中有很多关系。 一个讲座可以由几个讲师给,而讲师可以给几个课程。 我有课前存储的课程。 但是,我需要给讲师分配课程。 当我分配课程时,我也储存了这门课程的能力。 我的数据库图表: 我用冬眠和spring。 当课程分配任何讲师时,我需要一个hibernate映射。 我需要为容量字段添加值。 我的讲师映射: @Entity @Table(name="LECTURER") public class Lecturer { @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="LECTURER_ID_SEQ") @SequenceGenerator(name="LECTURER_ID_SEQ", sequenceName="LECTURER_ID_SEQ") private Long Id; @Column(name="NAME") private String name; @Column(name="SURNAME") private String surname; @Column(name="EMAIL") private String email; @Column(name="USERNAME") private String username; @Column(name="PASSWORD") private String Password; @ManyToMany @JoinTable( name="LECTURER_COURSE", joinColumns=@JoinColumn(name="LECTURER_ID"), inverseJoinColumns=@JoinColumn(name="COURSE_ID") ) private List<Course> courses; […]

为什么我需要configuration数据源的SQL方言?

当我们使用Hibernateconfiguration一个数据源时,我们应该添加hibernate.dialect属性(或者如果您使用的是EclipseLink,则添加eclipselink.target-database )。 我想知道方言的含义是什么? 我根据Hibernate的文档来configuration这个属性,但我不知道它的含义。

Hibernate映射包

我正在使用Hibernate注释。 在我所有的模型类中,我都是这样注解的: @Entity @Table public class SomeModelClass { // } 我的hibernate.cfg.xml是 <hibernate-configuration> <session-factory> <!– some properties –> <mapping package="com.fooPackage" /> <mapping class="com.fooPackage.SomeModelClass" /> </session-factory> </hibernate-configuration> 对于添加到com.fooPackage中的每个类,我都必须在hibernate.cfg.xml中添加一行,如下所示: <mapping class="com.fooPackage.AnotherModelClass" /> 有没有办法可以添加新的模型类,但不需要将此行添加到hibernate.cfg.xml?

org.hibernate.MappingException:无法确定types:java.util.List,在表:College,for列:

现在,我正在学习hibernate,并开始在我的项目中使用它。 这是一个CRUD应用程序。 我用所有的crud操作hibernate。 它适用于所有的人。 但是,一对多和多对一,我厌倦了尝试。 最后它给了我下面的错误。 org.hibernate.MappingException: Could not determine type for: java.util.List, at table: College, for columns: [org.hibernate.mapping.Column(students)] 然后我再次通过这个video教程 。 一开始我对我来说很简单。 但是,我不能让它工作。 现在也是这样说 org.hibernate.MappingException: Could not determine type for: java.util.List, at table: College, for columns: [org.hibernate.mapping.Column(students)] 我在互联网上跑了一些search,有人告诉它在Hibernate的一个错误 ,有人说,通过添加@GenereatedValue这个错误将被清除。 但是,nothings为我工作, 我希望我会得到一些修复! 谢谢! 在这里我的代码: College.java @Entity public class College { @Id @GeneratedValue(strategy=GenerationType.AUTO) private int collegeId; private […]

JPA和Criteria API – 只select特定的列

我只想select特定的列(例如SELECT a FROM b )。 我有一个通用的DAO,我想到的是: public List<T> getAll(boolean idAndVersionOnly) { CriteriaBuilder builder = manager.getCriteriaBuilder(); CriteriaQuery<T> criteria = builder.createQuery(entityClazz); Root<T> root = criteria.from(entityClazz); if (idAndVersionOnly) { criteria.select(root.get("ID").get("VERSION")); // HERE IS ERROR } else { criteria.select(root); } return manager.createQuery(criteria).getResultList(); } 错误是: The method select(Selection<? extends T>) in the type CriteriaQuery<T> is not applicable for the arguments […]