hibernate

Spring Transaction Management with Hibernate and MySQL, Global and Local

孤街浪徒 提交于 2021-02-20 19:18:08
问题 Im working on developing a webapplication with MySQL Server 5.1, Spring 3.0.5 and Hibernate 3.6. I use Springs Transaction Management. Im a newbie, so please be patient with me if I ask a question which is easy to answer. :-) 1) I read about global (xa) and local transactions. Is it correct, that global transactions mean transactions, which execute dataoperations on different resources (like different databases). And that local transactions execute dataoperations on only one resource

Spring-JPA中关于Entity继承的问题(上)

僤鯓⒐⒋嵵緔 提交于 2021-02-20 17:12:59
参考资料: https://developer.aliyun.com/article/312873 org.hibernate.WrongClassException:Object with [id=11] was not of the specified subclass: xxxx.entity(loaded object was of wrong class ... 这个错误其实是说,在构建当前的Entity1列表(LIST)的时候,发现该Entity所共用对象的另一个Entity2中,已经存在了id=11的对象,并且Entity1和Entity2的id=11的对象在结构上是不一样的,无法覆盖。 看到这个错误是不是有点蒙,像是在听天书的感觉?其实,这个Exception的本质是和JPA中hibernate的继承映射有关。 当前笔者的项目中,定义了BaseEntity,其中包含了code(编码),name(名称),elementcode(要素的tag)这些通用属性。然后,分别定义了Entity1和Entity2,且都集成自BaseEntity。Entity1和Entity2的的elementcode返回的内容不一样。举例子来描述的话,就相当于两组不同的字典要素,一个是桌子(Entity1,elementcode=桌子),一个是椅子(Entity2,elementcode=椅子)

How to remove all the duplicate results in Hibernate Search?

 ̄綄美尐妖づ 提交于 2021-02-20 09:31:13
问题 I'm using Infinispan with 6.0.2 with Hibernate Search 4.4.0. In the begining, after I execute a query like CacheQuery cq = SearchManager.getQuery(query,Hibernate.class).projection("id"); I use the cq.list() to get "id". But now the number of results reaches 300.000, because of the designing fo DB(cant change), the duplicate id is almost 29,000. I wrote this to get "id": for(int i=0;i<listObject.size();i++) { Object[] rdf = (Object[])listObject.get(i); if(!result.contains((String) rdf[0]))

How to remove all the duplicate results in Hibernate Search?

醉酒当歌 提交于 2021-02-20 09:27:45
问题 I'm using Infinispan with 6.0.2 with Hibernate Search 4.4.0. In the begining, after I execute a query like CacheQuery cq = SearchManager.getQuery(query,Hibernate.class).projection("id"); I use the cq.list() to get "id". But now the number of results reaches 300.000, because of the designing fo DB(cant change), the duplicate id is almost 29,000. I wrote this to get "id": for(int i=0;i<listObject.size();i++) { Object[] rdf = (Object[])listObject.get(i); if(!result.contains((String) rdf[0]))

Batch Insert with JPA and Spring

我只是一个虾纸丫 提交于 2021-02-19 11:43:21
问题 I'm using Spring Framework and JPA to insert beans into my database. I need to insert almost 8000 entities, and this can delay too much. Why should I disable "second level cache" in Hibernate hibernate.cache.use_second_level_cache false When I set a "hibernate.jdbc.batch_size 20" in Hibernate, will it insert my beans like this? INSERT INTO VALUES (1),(2),(3)...(20); INSERT INTO VALUES (21),(2),(3)...(40); The documentation says: "Hibernate disables insert batching at the JDBC level

Is there a way to copy @id column generatedValue to another column of same entity?

我是研究僧i 提交于 2021-02-19 08:50:27
问题 I have a requirement in SpringBoot JPA service where the primary key value of the column must be stored in another column of same entity. In example below, rowId is generated by StringPrefixedLineSequenceIdGenerator . Whatever value it generates, I need to store the same in lineId column. @Entity @Table(name="CX_LINE") public class CXLine { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cx_line_seq") @GenericGenerator( name = "cx_line_seq", strategy = "com.tmo.chub

Hibernate and antlr.RecognitionException not found

戏子无情 提交于 2021-02-19 08:27:11
问题 I want to learn Hibernate. I found some tutorial, but I have one issue with launching the project. This is my pom: <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> <version>6.2.1.jre8</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.3.5.Final</version> </dependency> <dependency> <groupId>antlr</groupId> <artifactId>antlr</artifactId> <version>2.7.7</version> </dependency> <

ManyToOne annotation to specific column

£可爱£侵袭症+ 提交于 2021-02-19 08:06:43
问题 I am trying to create the follow structure using Hibernate with annotations: To create a ManyToMany relationship I had created two classes called SessionRiu and SessionRiuId (pk). This way the Session class has two foreign keys (agend_id and user_id) but when I try to create the OneToMany from operation the hibernate does not create the foreign using the id from session: Session FKs: Operation FKs ( empty ): As I am beginner in java and hibernate, I would appreciate any suggest about my code.

How to configure multiple schemas with Hibernate

早过忘川 提交于 2021-02-19 06:43:46
问题 We have got a requirement for multiple schemas in Hibernate. In our project, we need to connect to multiple schemas based on the username and password. But how to configure multiple schemas in Hibernate? Please let me know if there's a way. 回答1: Thanks to Hibernate Multitenancy support, you can easily do that as follows: The following examples can be found in the Hibernate ORM documentation folder. Each schema can be a tenant, so you only need to provide a tenant identifier to the Hibernate

how to mapping an OneToMany relation with Weak Entity in Hibernate

三世轮回 提交于 2021-02-19 05:43:05
问题 I need to map a OneToMany relationship in hibernate, with the JPA annotations, in which is involved a weak entity. For example Table orders: CREATE TABLE orders( idorder serial NOT NULL, note varchar(30), CONSTRAINT orders_pkey PRIMARY KEY (idorder) ) Table OrderItems: CREATE TABLE orderitems( idorder integer NOT NULL, iditem serial NOT NULL, qnt integer, CONSTRAINT orderitems_pk PRIMARY KEY (idorder, iditem), CONSTRAINT fk_orderitems FOREIGN KEY (idorder) REFERENCES orders (idorder) MATCH