Expand my Community achievements bar.

Using Hibernate as a Custom Component

Avatar

Former Community Member

I don’t know whether this question is appropriate in LC context.

Our scenario, We have very complex logic in each of JDBC store/retrieve activity in the process. We would like to move this part into Hibernate based custom component.

We tried with simple Hibernate persistence class but it seems to be LC not loading them.

1)      Is this the restriction with LC? (using hibernate as a custom component)

2)      What is the appropriate solution?

You help is highly appreciated

7 Replies

Avatar

Level 10

1)      Is this the restriction with LC? (using hibernate as a custom component)

There are no restrictions that I'm aware of. A custom component is just a POJO, so any you can write in Java you can put in a custom component.

2)      What is the appropriate solution?

     That seems like a good solution to me.

Jasmin

Avatar

Former Community Member

Jasmin,

When I try to load an annotated entity class from my custom component , It seems to be not loading the class ,

I'm getting class not found exception .

I have not tried with .hbm file

Thanks

Avatar

Level 10

Is your class included in the custom component?

Is the jar referenced in the class patch section of the component.xml?

Jasmin

Avatar

Former Community Member

Jasmin,

Is your class included in the custom component?

Yes, It is a annotated entity class,

When creating sessionFactory it is not loading the class.

i'm using flowing code block for creating sessionFactory,

factory =

new AnnotationConfiguration()

.addAnnotatedClass(dao.entity.UserEntity.

class)

.setProperty(

"hibernate.dialect",m_dialect )

.setProperty(

"hibernate.connection.driver_class", m_driverClass)

.setProperty(

"hibernate.connection.url", m_connectionUrl )

.setProperty(

"hibernate.connection.username",m_userName)

.setProperty(

"hibernate.connection.password", m_password)

.setProperty(

"hibernate.hbm2ddl.auto", m_hbmTodll )

.setProperty(

"current_session_context_class",m_contextClass )

.configure(resource).buildSessionFactory();



Is the jar referenced in the class patch section of the component.xml?

Yes , I have tried for this approch too , but class is entity class is not loaded.

Avatar

Former Community Member

When I try to execute from LC process, I'm getting the following error :

dao.HibernateConnectionFactory] Creating new SessionFactory createSessionFactory()
2010-08-05 11:54:34,880 ERROR [STDERR] org.hibernate.MappingException: entity class not found: dao.entity.UserEntity
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:99)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123)

But the same code working fine in Test cases.

Avatar

Level 10

When you create your jar, make sure the "Compress the content" option is not selected.

Jasmin

Avatar

Former Community Member

Yes ! there is no problem in Jar, if I remove that Hibernate Part everything working perpectly !!

even I tried with .hbm.xml it is not woking ..