Tag: jpa

Wrong SQL update query generated on merge

When using EntityManager’s merge method on WebSphere Application Server 7 with MS SQL Server 2008 to update entity in database, wrong SQL query being generated (no update parameters after SET keyword (see stacktrace below)). Most likely this issue occurs when I’m trying to merge entity with no changes regarding DB, but this aint gettin me […]

jpa mssql create datetime column with TemporalType.TIMESTAMP and portability

I have an entity with a following column definition: @Temporal(TemporalType.TIMESTAMP) private Date dateStart; @Temporal(TemporalType.TIMESTAMP) private Date dateEnd; In derby jpa automatically create TIMESTAMP columns. When I want to use the same application with Microsoft SQL Server, I have problem, because jpa automatically create column with TIMESTAMP type. In MSSQL only one TIMESTAMP column per table […]

jpa mssql @Lob and create 2GB columns with portability

I would like to create BLOB field in application tables usign JPA. I have to support multiple databases (Derby, Microsoft SQL Server). When I define @Lob fields as: @Lob private byte[] fileData; JPA creates default size of BLOB fields regarding each RDBMS. In MSSQL i have FILEDATA BLOB with default size 8000 bytes. Which is […]

Efficient way to check if record (from a large set of data) is existing in the Database (JPA/Hibernate)

We have a large set of data (bulk data) that needs to be checked if the record is existing in the database. We are using SQL Server2012/JPA/Hibernate/Spring. What would be an efficient or recommended way to check if a record exists in the database? Our entity ProductCodes has the following fields: private Integer productCodeId // […]

Hibernate JPA – Make Unique constraint but ignore null or empty

Is there any annotation or setting to which I can make a set of columns unique but ignore that constraint if null or empty. For example, saleId itemNumber I want these two items to be unique, but the itemNumber can have all nulls until itemNumbers are assigned later. Other than a programmatic solution, is there […]

Error when setting IDENTITY_INSERT on sql server table

As I had mentioned in this post JPA SET IDENTITY_INSERT not working that I was successful in using the SET IDENTITY_INSERT query for my purposes. But today after I have managed to configure connection pooling i am getting this type of error. java.sql.SQLException: IDENTITY_INSERT is already ON for table ‘mydb.dbo.[table1]’. Cannot perform SET operation for […]

how to get only selected table from stored procedures?

I have a stored Procedure like the following CREATE PROCEDURE [dbo].[spConfiguration_test] @ID int AS select empid,name from employee; select * from address; I wanted to call this stored procedure from jpa.So I did like this DAOcode public List test() { String execProce=”exec spConfiguration_test 1″; System.out.println(execProce); Query query = entityManagerUtil.entityManager.createNativeQuery(execProce); return query.getResultList(); } service class Code […]

c3p0 do not timeout when are impossible to reach the host

The first thing my program do when open is try to connect in the database, if the c3p0 wont connect it freezes and do not raise any error message. The weird thing is that with MySql I got java.net.UnknownHostException, but with SqlServer nothing, it keeps trying forever. I want to catch the error and do […]

Database reverse engineering tool with columnDefinition support

I am trying to generate entities from a MSSQL database. I tried in eclipse and intellij idea with the built in tools for entities generation from database but I am having some issues with the generated entities. char, nvarchar fields are mapped as string and the @Column annotation doesn’t contain the columnDefinition (e.g. columnDefinition = […]

JPA truncates nanoseconds when using date criteria & SQL datetime2

I’m trying to create a where clause involving a SQL Server datetime2 field (accurate to 100 nanoseconds); using JPA & Hibernate. My code looks something like this: CriteriaBuilder cb = em.getCriteriaBuilder(); List<Predicate> predicates = new ArrayList<>(); CriteriaQuery(X) q = cb.createQuery(X.class); Root<X> root = q.from(X.class); java.sql.Timestamp mySqlTimeStamp = Timestamp.valueOf(“2015-06-04 11:31:53.2119339”); predicates.add(cb.greaterThan(root.get(“DateModified”), mySqlTimeStamp)) q.where(predicates.toArray(new Predicate[predicates.size()])); em.createQuery(q).getResultList(); SQL […]

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