Hibernate

Working with Hibernate and DB2 9, if you have a byte[] member in your entity which is supposed to be mapped to a BLOB column, you'll probably get:

ERROR [org.hibernate.util.JDBCExceptionReporter] - <DB2 SQL Error: SQLCODE=-301, SQLSTATE=07006, SQLERRMC=2, DRIVER=3.61.75>
ERROR [org.hibernate.event.def.AbstractFlushingEventListener] - <Could not synchronize database state with session>
org.hibernate.exception.SQLGrammarException: could not insert...

Which in general means wrong data type!

After throwing lots of hooks into the sea of Google & IBM, I came up with this one - thanks to Steve for his excellent fish

www.badlildog.com/words/

avim 08/02/2011 - 11:47

Kauklahti is an open source tool aiming to keep ORM simple. It integrates with Spring JdbcTemplate and works like BeanPropertyRowMapper. But it also supports table joining and full CRUD generation.

itaip 28/10/2009 - 08:54
Hi we have a User entity with a password field, and two use cases: 1) update the user entity but not the password field, the entity is sent from the UI and has null in the password field. 2) update the user entity including the password,again the entity is sent from the UI.   in both use cases it is assumed that the entity is not attached to the hibernate session.   so using just saveOrUpdate in the first use case will set null to the password field in the DB(I'm ignoring the DB constraints for now), and my understanding is that hibernate merge is not the solution. my question is how to implement it without having to do two round trips to the DB and without having to write HQL statements.   my thoughts where to use the Seppuku pattern: have two entity classes mapped to the same table User UserWP extends User
shalom 04/06/2009 - 01:28

I'm working on a legacy DB I have no control over, in my code I have an entity "User" which is mapped to a table in the DB, User has a User.role field, this filed is an Enum:

 

public enum UserRole{ ADMIN,SUPERADMIN.....}

User has the following mapping

 

@Column(name="user_role")
@Enumerated(EnumType.STRING)
private UserRole role;

the problem is that the DB is inconsistent, in the DB i might some times get user_type as one of the following:

 

liorb 13/12/2010 - 12:12

Hi,

For a client I need to support the following using either Hibernate or some other variant maybe using CGLIB or ASM or freemaker:

The system should support update of the database schema and Hibernate mapping at runtime. Meaning, if I have a Hibernate entity "Animal" with properties A and B I should support the addition and deletion of properties during runtime. e.g. after the transformation the Entity can have property A deleted and property C added. This means of course that :

1-The Entity *Class* itself should be re-generated in memory on the fly with **JPA annotations** for each field. I started testing using CGLIB and one other option is FreeMaker for generating a java source file and then compiling it at runtime.

Recommendations are highly regarded.

2-After that I need somehow to unload the existing "Animal" instances, stop all pending transactions which reference those classes and then

shlomo 29/06/2010 - 13:23

And a bunch of other excellent posts.  Worth reading  for anyone dealing with Hibernate or JPA.

 

http://blog.xebia.com/2009/04/09/jpa-implementation-patterns-removing-en...

 

shlomo 22/06/2009 - 09:06

Hi

we have a spring/hibernate -> swing application
the communication is soap with axis, the hibernate entities are mapped to soap objects and travel from the server to the client and back.

we have some entities that we don't want to select all the fields every time, in some cases we need only partial data of the entity.
for example a Profile entity with id,name ,description and many other primitive and non primitive fields,
the UI people do not want to deal with a Profile object when they need only part of the data, they want for example a ProfileIdentifier object that has the profile id,name and description.

ProfileIdentifier
    id
    name
    desc

so we can do it with inheritance
class Profile extends ProfileIdentifier

or with a ProfileIdentifier component or value type,

shalom 08/06/2009 - 15:31

hi,

While working on a web app which included a Hibernate module,  I had to write a JMX client that communicates with another server instence.

After writing the client (using JBoss's RMIAdaptor), I wanted to test it, so I started adding JBoss dependencies to my project's pom.xml. At about the the 5th one, I stopped and reverted to the one jar that is supposed to rule them all: jbossclient-all.jar. While running the test, however, I got:

java.lang.NoSuchMethodError: org.hibernate.cfg.ExtendedMappings.getReflectionManager()Lorg/hibernate/reflection/ReflectionManager;

Indeed, the above jar contained some Hibernate classes (Hibernate classes? in a client jar? wtf?) - which were probably the reason for the graceful(not) behavior. My question: has anyone tackled this issue before? has anyone written jboss-specific JMX code and had to resolve the dependency issues?

 

cheers,

 

zvika 27/04/2009 - 23:18

Hi,

In our application we have a JSF tree which displays the hierarchy of our entities. Whenever the relationship between parent and child is changed in the database, we immediately synchronize the state with the tree.

We recently added EhCache as our second level cache implementation, both for Entities and Collections. It turns out that even if you add a new entity that is involved in a parent child relationship, the Collection that resides in the cache will NOT be updates and so you will have a dirty version.In our case that resulted in a tree that does not reflect the true stat of the DB.

What needs to be done is to use the session factory to evict to parent entity and then to evict the collection from the cache. Only then will it be updated again and reflect the true state of the DB. I followed the code suggested here:

http://jaitechwriteups.blogspot.com/2006/08/evict-collection-from-hibern...

shlomo 25/03/2009 - 10:56

Recently I had to convert a system to be fully UTF8 compliant accross all tiers. Folowing are the instructions needed to make your system do the same and support multiple languages. I tested our system with 4 different languages including Hebrew, German, Arabic and Russian.

 

This file is a standard JPA file: /META-INF/persistence.xml

<property name="hibernate.connection.useUnicode" value="true"/>
<property name="hibernate.connection.characterEncoding" value="UTF-8" />

This file is relevant to anyone using seam: page.xhtml

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>

This is a custom MYSQL file that must be executed before you attempt inserting UTF8 charecters using mysql client :utfsupport.sql

shlomo 09/02/2009 - 12:13
Syndicate content