jpa-2.0

Bulk insertion of CollectionTable elements in Hibernate / JPA

和自甴很熟 提交于 2021-02-10 09:45:44
问题 We are using Hibernate 4.2 as the backing library for JPA 2.0 entities. We have an entity like the following: @Entity public class MyEntity { .... @ElementCollection @MapKeyColumn(name = "key") @Column(name = "value") @CollectionTable("MyEntityMap") private Map<String, Integer> theMap; ... } The map potentially has thousands of entries. I have set hibernate.jdbc.batch_size=50 , but Hibernate still generates an insert statement for each entry in the map, when I say entityManager.persist

Bulk insertion of CollectionTable elements in Hibernate / JPA

梦想的初衷 提交于 2021-02-10 09:45:31
问题 We are using Hibernate 4.2 as the backing library for JPA 2.0 entities. We have an entity like the following: @Entity public class MyEntity { .... @ElementCollection @MapKeyColumn(name = "key") @Column(name = "value") @CollectionTable("MyEntityMap") private Map<String, Integer> theMap; ... } The map potentially has thousands of entries. I have set hibernate.jdbc.batch_size=50 , but Hibernate still generates an insert statement for each entry in the map, when I say entityManager.persist

JPA+ORACLE: Can't pass boolean param to my stored procedure

旧时模样 提交于 2021-02-10 05:42:05
问题 I can not pass boolean param to my stored procedure in Oracle. If I set value directly in the query text (mypackage.Test(?, false, ?, ?);) all work fine... jdbc-driver: ojdbc6.jar container: Tomcat 7.0.28 hibernate-core+hibernate-entitymanager: 4.1.6.Final oracle: Oracle Database 11g Release 11.2.0.2.0 - 64bit Production Here my realization: EntityManager em = defaultFactory.createEntityManager(); em.createNativeQuery("BEGIN mypackage.Test(?, ?, ?, ?); END;")// .setParameter(1, factId)//

How does Hibernate Metamodel Generator work?

梦想与她 提交于 2021-02-08 10:06:10
问题 Recently just making a move from Hibernate Session api to JPA2. I am assuming it should be some setup problem. But basically my eclipse does not recognize Metamodel attribute. For example: builder.like( root.get(Book_.name) , search) Book_ can not be resolved as variable. Now I have followed this http://hibernate.org/orm/tooling/ and added <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-jpamodelgen</artifactId> <version>5.2.6.Final</version> </dependency> As it stated here

JPA Hibernate - Mapping Embedded Collections to a Single Table

守給你的承諾、 提交于 2021-02-08 05:57:34
问题 I have a table with lot of fields such as Account OrderNo Term LegNo LegSymbol LegSymbolType LegExchangeType etc etc The primary key of the above table is a composite key comprising of Account, OrderNo & LegNo The data in the DB would look something like this 1234 1 2 1 AAA BBB CCC 1234 1 2 2 DDD EEE FFF The bolded ones are Account,Order,LegNo respectively. While designing the entity for the above table, we want to group all the Leg related information (All bolded columns ) in a separate

Custom @Column JPA Annotations, how to?

左心房为你撑大大i 提交于 2021-02-08 03:47:32
问题 Been trying hard to search for a solution to create some Custom JPA Annotations to replace repetitive fields when declaring Entity POJOs. Any help? Here what I am trying to achieve: //@Column(name = "is_enabled", nullable = false, columnDefinition = "tinyint(1) DEFAULT 1") @ColumnBooleanNotNullDefaultOne private Boolean isEnabled; or //@Column(name = "created", nullable = false, updatable = false, insertable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP") @ColumnTimestamp

org.hibernate.criterion.Example use with CriteriaQuery

主宰稳场 提交于 2021-02-07 18:18:17
问题 I have following code that I need to refactor for use in hibernate 5. This includes removing every deprecated call. public List<T> findByExample(T example, String... excludeProperty) { Criteria crit = session.createCriteria(T.class); Example ex = Example.create(example); for (String exclude : excludeProperty) { ex.excludeProperty(exclude); } crit.add(ex); return crit.list(); } Since createCriteria is deprecated I was going to replace it with getSession().getCriteriaBuilder().createQuery(Foo

JPA: TypedQuery sometimes returns null instead of NoResultException

房东的猫 提交于 2021-02-07 12:35:27
问题 Usually I work with NoResultException to return an "empty" object, e.g. an empty error list or new BigInteger("0"), if I get no results from a TypedQuery. Now it turned out that this sometimes doesn't work. Suddenly getSingleResult() returns null instead of causing a NoResultException, and I don't understand why. Look this example: public BigInteger pointsSumByAccountId(long accountId) { try { TypedQuery<BigInteger> pointsQuery = entityManager.createNamedQuery(Points.SumByAccountId,

Spring Transaction with JNDI and JPA transaction manager

天大地大妈咪最大 提交于 2021-01-28 21:11:01
问题 I have defined DataSource in Context.xml(JNDI) and i would like to use with JPA transaction manager in Spring application Context.xml. I don't want to use JTA Transaction since i am using tomcat server. Could anyone help me how can i achieve this with an example? I am using @transactional annotations in DAO's and services. Regards Vijay 回答1: you can Define DataSource: Use JndiObjectFactoryBean class. To define the data source by providing JNDI binding name. <!– Data Source JNDI –> <bean id=

How to perform a join fetch in JPA Criteria without unchecked casting?

邮差的信 提交于 2021-01-28 06:30:15
问题 I need to do a JOIN FETCH in JPA Criteria using a static metamodel, however I'm at a loss on how to do it without getting an unchecked exception warning. Suppose we have a Thing entity with a lazily-initialized Other entity inside it. I want to retrieve Things with fetched Others, where other.someField="someValue". This is roughly how I would do it: public List<Thing> getThings() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Thing> cq = cb.createQuery(Thing.class); Root root =