Posts

Showing posts with the label jpa

JPA 2.1 – Features every developer should know

Features and Enhancements in JPA 2.1 Named Stored Procedure Query Sometimes it is easier or more efficient to use a stored procedure to perform the operations within the database. Before JPA 2.1 the only way to call a stored procedure was to use a native query. The newly introduced  @NamedStoredProcedureQuery  can now be used to annotate a query to call the stored procedure.  more details in  How to call stored procedures in JPA . Stored Procedure Query The Stored Procedure Query is an alternative way to implement a stored procedure call without using annotations. For this purpose the  EntityManager  was extended by the  createStoredProcedureQuery(String procedureName, Class… resultClasses)  method. You can read more about it in  How to call stored procedures in JPA – Part 2 . Attribute Converter Attribute Converter provide a nice and easy way to define a custom mapping between your property on the entity and the databas...

PostgreSQL bytea and oid

I came across with following issue when i'm trying to save the uploaded file in to the database as a byte array using hibernate, JPA 2.0  annotation with Postgre SQL. even though in this stage i'm pretty much new to Postgre SQL, It has two type of data types to represent the binary data or BLOB, since i'm using hibernate jpa annotations use the annotation @Lob to indicate the byte[] of data to persist as a binary data. @Lob   @Basic(fetch = FetchType.LAZY)  public byte[] getPicture() { return picture;  }    exception : java.sql.SQLException: ERROR: column "picture" is of type bytea but expression is of type oid   Then i understood the issue with the data types.but when the hibernate generating the table it creates the  column with data type "oid" , after removing this annotation it creates a table column with "bytea" data type. and i'm in doubt which would be the most suitable data type to use.   Then i found the difference...