Nulls last in hibernate 3.6 GA and Spring 4 - java

I am using PostgreSQL database with Hibernate and Spring Rest.
I am getting sorted data in Hibernate Criteria from Postman but when data is sorted on descending order the NULL values come first, I believe this may be how PostgreSQL is sending data to Hibernate.
I know in Hibernate 4.2.x and 4.3.x there are ways to implement this using Order as shown below
Criteria criteria = ...;
criteria.addOrder( Order.desc( "name" ).nulls(NullPrecedence.LAST) );
But there is no similar implementation in 3.6 as I was getting compilation when I tried the same.
From Hibernate order by with nulls last I tried setting the Hibernate properties:
hibernate.order_by.default_null_ordering=last
It did not help me.
I am setting it as Hibernate configuration parameter, but it's not working.
I have to modify legacy code which is using Criteria so how can I implement NULLs ordering while using Criteria in Hibernate 3.6?

Related

I have to show the all values in lookup tables values as dropdown in UI I am using hibernate session query and I am storing in cache

But the cache is not storing values its querying each Tuple(line) of database which is even worse than implementing cache
I have done this steps
Marking entity as #Cachable and #Cache(read only , my region)
and session(set Cachable = true)
In hibernate configuration I have set use query cache= true
I am using ehcache
I want all the my POJO objects from the database table using cache someone please help me
Thanks in advance
this may be caused with many reasons, first of all, are you config query cache in your configuration XML file (witch is hibernate.cfg.xml in pure Hibernate project or persistence.xml in JPA Project)

JPA / Hibernate: StringClobType deprecated

I recently upgraded Spring Boot and with this came a hibernate upgrade. Unfortunately, the entity column #Type(StringClobType) annotation has been deprecated. The documentation tell me I need to switch it to MaterilizedClobType.
Unfortunately this has broken my application.
I'm using PostgreSQL 9.5. The StringClobType annotation created a text type in the database which allowed me to store long text in the field. Unfortunately now, the string literal comes back when Hibernate is expecting some kind of LOB id.
This gives the error: Bad value for type long
The Hibernate #Type value that maps to PG's Text data type is org.hibernate.type.TextType. This is what you should use.
For what it's worth, this a sibling of org.hibernate.type.MaterializedClobType, which maps to CLOB; both are subclasses of org.hibernate.type.AbstractLongStringType.

How to select schema at runtime using Hibernate?

I already have an existing code base, where schema(like db_1, db_2..) are created at run time.
We are currently using JdbcTemplate, using that its quite easy to append schema in the native SQL queries some thing like :-
sql = " Select * from "+schema+".user";
jdbcTemplate.query(sql, new UserMapper());
Now I want to know is how to provide schema to hibernate at runtime like I did with the jdbcTemplate?
What connection url should I provide in hibernate.cfg.xml so that it doesn't connects to a single schema rather whole database?
Any suggestions will be helpfull.
P.S: I am new to hibernate (So I might have missed something stupid)
I know of two options:
Use native SQL query binding results to JPA entities. Details here.
Use Hibernate multi-tenancy. Details here and here.
Although I haven't tried either.

Jsf DataModel Impl That Supports Paging with JPA

I need a javax.faces.model.DataModel implementation that retrieves table page elements using a JPA SELECT query as the user scrolls to a new page in the data table.
Something like javax.faces.model.ResultSetDataModel but it shall uses JPQL to fetch elements. Or is there a way to use javax.faces.model.ResultSetDataModel in JPA environment?
Thanks
I have an example on GitHub showing a custom DataModel that supports paging and selection of items. Have a look at the SelectableDataModel and PageableDataModel where the paging is done.
Those custom DataModel classes use a DataProvider to fetch the paged data from anywhere. In the example I use a DataProvider implementation to get data from a DB via JPA.
I created this example for a session at the JAX 2011. The slides for this session are available too, but only in German.
The example is built with MyFaces 2.1.3, OpenWebBeans (CDI), Hibernate (JPA) and an in memory Derby DB.

Are Hibernate filters only applied after the data has been loaded from db?

I've found some contradicting information on the net. Does anyone know whether Hibernate filters affect the generated sql, or is it just filtering the data as it's read from the database?
Hibernate filters affect the where clause of the generated SQL.
The Introduction to Hibernate Filters is a nice article on filters and provides a demo application allowing to play with them.
If you enable SQL in Hibernate using show_sql"(+"format_sql"),
and execute query with enabled filter, you will see the result.
For example:
select
item0_.ID as ID0_
from
ITEMS item0_
where
item0_.deleted = 'FALSE' <-- here is filtering

Categories

Resources