Tag: jpa

JPA – Create Transient primary key

I have an entity class mapped to an existing table. This table doesn’t have a primary key. Here is the table : CREATE TABLE [dbo].[testtable]( [field1] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [field2] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [field3] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [field4] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [field5] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, […]

Add a foreign key to composite primary key and changes in JPA Entity class

I have a class User with primary key (id) which corresponds to ‘user’ table in SQL Server database. My User class has a many to one relationship with Project Entity. public class User{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = “id”) private Integer id; @JoinColumn(name = “project”, referencedColumnName = “id_project”) @ManyToOne(optional = false) […]

SQL Stored Procedure Exception Not Found in JAVA

Throwing exception from sql stored procedure catch block is not raising exception in java layer for SP1 while for SP2 exception raised. When I am executing both SPs are giving exception in SQL Server but from java code I got no exception for SP1. I am calling both SPs using JPA StoredProcedureQuery and using Hibernate […]

JPA and SQL Server column encryption

I’m using WebSphere 7 and their JPA 2.0 implementation which is based on OpenJPA, and I have something driving me crazy. I have to connect to a SQL Server 2008 database that uses the database column encryption. The encryption is done by several database commands: 1 – OPEN SYMMETRIC KEY DECRYPTION BY CERTIFICATION 2 – […]

Persistence.createEntityManagerFactory takes ages

I have a DBUnit test which runs OK, but is taking ages (4-5 mins) to create the entity manager factory. I am using JPA with hibernate and SQL serve. Would be of great help if anybody could throw some light on this. My machine seems faster to blame it on Sql server 🙂 Here is […]

EclipseLink generated SQL doesn't include pagination

(My environment: Windows 7 x64 and Server 2008, EclipseLink 2.5.2, I’ve tried the following with JTDS and the MS JDBC driver, and with MS SQL Server Express 2008 and 2012.) I’m doing a paginated query in a table with anywhere from 5-50 million rows, with about 5 million rows matching the filter criteria. The following […]

How do you auto-commit an SQL Server transaction in JPA?

Why do I need to use a transaction to persist an Entity? Is there something I can add to my persistence.xml to auto-commit? This doesn’t insert: em.persist(this); But this does: em.getTransaction().begin(); em.persist(this); em.getTransaction().commit(); I guess my initial reference point was this GWT doco public void persist() { EntityManager em = entityManager(); try { em.persist(this); } […]

OpenJPA 1 – sequence table not being created

I have an entity class with the following annotation on its primary key: @GeneratedValue(strategy = GenerationType.AUTO). However, when I try to persist an instance of this class, I get com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name ‘OPENJPA_SEQUENCE_TABLE’. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197) The table it’s looking for definitely does not exist in the database. The user it’s connecting to the database […]

Convert float/int to Calendar in jpa hibernate SQL Server

I’m developing a Java project with JPA / Hibernate and SQL Server DB. I got an existent db where date fields are stored as int and datetime as float. Does anyone know how can I implement a transparent conversion to a Calendar type in my domain class? I must calculate the date in getter and […]

Hibernate (/JPA) server-side paging and MS SQL Server

I implementing a server-side data paging with hibernate / JPA, the underlying database is MS SQL Server 2008. The SQL is generated like this: criteria.setFirstResult(pagingParams.getDisplayStart()) .setMaxResults(pagingParams.getDisplayLength()); (The main work lays in creating the appropriate filter / sorting, but that’s not relevant here) What I’m observing is the following SQL: page (0-20): select top 20 this_.id […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.