<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Adding a new Hibernate DataSource with annotations</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=4214424" />
  <subtitle>Adding a new Hibernate DataSource with annotations</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=4214424</id>
  <updated>2026-04-06T22:03:41Z</updated>
  <dc:date>2026-04-06T22:03:41Z</dc:date>
  <entry>
    <title>RE: Adding a new Hibernate DataSource with annotations</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4216761" />
    <author>
      <name>Luca Bernard</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4216761</id>
    <updated>2009-11-02T18:18:20Z</updated>
    <published>2009-11-02T18:18:20Z</published>
    <summary type="html">&lt;div class="quote-title"&gt;Luca Bernard:&lt;/div&gt;&lt;blockquote&gt;Hi all,&lt;br /&gt;&lt;br /&gt;Just an update; when i start the portal i get the following error:&lt;br /&gt;&lt;br /&gt;org.springframework.beans.factory.BeanCreationException: Error creating bean with name &amp;#39;sessionFactory&amp;#39; defined in class path resource [persistence.hibernate.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: configurationClass must be assignable to [org.hibernate.cfg.Configuration]&lt;br /&gt;Caused by: &lt;br /&gt;org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: configurationClass must be assignable to [org.hibernate.cfg.Configuration]&lt;br /&gt;&lt;br /&gt;I suspect that this is a classpath clash. I&amp;#39;ve used hibernate-core-3.3.2,  hibernate-annotations-3.4.0, hibernate-validator-3.1.0.&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Ok to fix this i needed some of the dev libs in portal. Moreover seems that annotation are required to be 3.2.x. &lt;br /&gt;&lt;br /&gt;Now portal runs and registers all my beans. &lt;br /&gt;&lt;br /&gt;But still trying to figure out how to access them from a portlet.&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Luca</summary>
    <dc:creator>Luca Bernard</dc:creator>
    <dc:date>2009-11-02T18:18:20Z</dc:date>
  </entry>
  <entry>
    <title>RE: Adding a new Hibernate DataSource with annotations</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4215812" />
    <author>
      <name>Luca Bernard</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4215812</id>
    <updated>2009-11-02T15:16:17Z</updated>
    <published>2009-11-02T15:16:17Z</published>
    <summary type="html">&lt;div class="quote-title"&gt;Luca Bernard:&lt;/div&gt;&lt;blockquote&gt;Hi all,&lt;br /&gt;&lt;br /&gt;I&amp;#39;ve put data model POJOs (those in ns &amp;#34;it.myds.datalayer.domainmodel.*&amp;#34;) in ext-services/src.&lt;br /&gt;I&amp;#39;ve also added some libraries to ext-lib/development:&lt;br /&gt;• /ext/ext-lib/development/commons-lang-2.4.jar&lt;br /&gt;• /ext/ext-lib/development/ejb3-persistence.jar&lt;br /&gt;• /ext/ext-lib/development/hibernate-annotations.jar&lt;br /&gt;• /ext/ext-lib/development/hibernate-core.jar&lt;br /&gt;• /ext/ext-lib/development/hibernate-entitymanager.jar&lt;br /&gt;• /ext/ext-lib/development/hibernate-validator.jar&lt;br /&gt;&lt;br /&gt;I&amp;#39;ve build and redeployed ext and all went successfully at compile time.&lt;br /&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Just an update; when i start the portal i get the following error:&lt;br /&gt;&lt;br /&gt;org.springframework.beans.factory.BeanCreationException: Error creating bean with name &amp;#39;sessionFactory&amp;#39; defined in class path resource [persistence.hibernate.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: configurationClass must be assignable to [org.hibernate.cfg.Configuration]&lt;br /&gt;Caused by: &lt;br /&gt;org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: configurationClass must be assignable to [org.hibernate.cfg.Configuration]&lt;br /&gt;&lt;br /&gt;I suspect that this is a classpath clash. I&amp;#39;ve used hibernate-core-3.3.2,  hibernate-annotations-3.4.0, hibernate-validator-3.1.0.&lt;br /&gt;&lt;br /&gt;Any hints ?</summary>
    <dc:creator>Luca Bernard</dc:creator>
    <dc:date>2009-11-02T15:16:17Z</dc:date>
  </entry>
  <entry>
    <title>Adding a new Hibernate DataSource with annotations</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4214423" />
    <author>
      <name>Luca Bernard</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=4214423</id>
    <updated>2009-11-02T10:35:25Z</updated>
    <published>2009-11-02T10:35:25Z</published>
    <summary type="html">Hi all,&lt;br /&gt;&lt;br /&gt;i need some hints on how to proceed to build my application.&lt;br /&gt;&lt;br /&gt;I&amp;#39;ve an already existing data layer comprised of:&lt;br /&gt; - domain model POJOs classes annotated with JPA annotation (plus some hibernate3 specifics)&lt;br /&gt; - a generic DAO layer&lt;br /&gt; - some components using the DAOs to implement higher level business intelligence.&lt;br /&gt; &lt;br /&gt;I would like to integrate these in liferay but all the guides end up to use service.xml to define entities, tables and so on.&lt;br /&gt;&lt;br /&gt;What i would do is to expose a new data source, the annotated POJOs classes and the DAOs as spring beans towards the portlet layer.&lt;br /&gt;&lt;br /&gt;Till now i&amp;#39;ve done the following:&lt;br /&gt;&lt;br /&gt;In the portal-ext.properties i&amp;#39;ve defined the new data source &amp;#34;myds&amp;#34;&lt;br /&gt;&lt;br /&gt;file: /ext/ext-impl/portal-ext.properties&lt;br /&gt;#    jdbc.myds.driverClassName=org.postgresql.Driver&lt;br /&gt;#    jdbc.myds.url=jdbc:postgresql://localhost:5432/myds&lt;br /&gt;#    jdbc.myds.username=myds&lt;br /&gt;#    jdbc.myds.password=myds&lt;br /&gt;&lt;br /&gt;In the file ext-spring.xml i&amp;#39;ve put the following beans definitions:&lt;br /&gt;&lt;br /&gt;	&amp;lt;bean id=&amp;#34;mydsDataSource&amp;#34;&lt;br /&gt;		class=&amp;#34;org.springframework.jdbc.datasource.DriverManagerDataSource&amp;#34;&amp;gt;&lt;br /&gt;		&amp;lt;property name=&amp;#34;driverClassName&amp;#34;&amp;gt;&lt;br /&gt;			&amp;lt;value&amp;gt;org.postgresql.Driver&amp;lt;/value&amp;gt;&lt;br /&gt;		&amp;lt;/property&amp;gt;&lt;br /&gt;		&amp;lt;property name=&amp;#34;url&amp;#34;&amp;gt;&lt;br /&gt;			&amp;lt;value&amp;gt;jdbc:postgresql://localhost/myds&amp;lt;/value&amp;gt;&lt;br /&gt;		&amp;lt;/property&amp;gt;&lt;br /&gt;		&amp;lt;property name=&amp;#34;username&amp;#34;&amp;gt;&lt;br /&gt;			&amp;lt;value&amp;gt;myds&amp;lt;/value&amp;gt;&lt;br /&gt;		&amp;lt;/property&amp;gt;&lt;br /&gt;		&amp;lt;property name=&amp;#34;password&amp;#34;&amp;gt;&lt;br /&gt;			&amp;lt;value&amp;gt;myds&amp;lt;/value&amp;gt;&lt;br /&gt;		&amp;lt;/property&amp;gt;&lt;br /&gt;	&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;	&amp;lt;bean id=&amp;#34;mydsNamingStrategy&amp;#34;&lt;br /&gt;		class=&amp;#34;org.springframework.beans.factory.config.FieldRetrievingFactoryBean&amp;#34;&amp;gt;&lt;br /&gt;		&amp;lt;property name=&amp;#34;staticField&amp;#34;&amp;gt;&lt;br /&gt;			&amp;lt;value&amp;gt;org.hibernate.cfg.ImprovedNamingStrategy.INSTANCE&amp;lt;/value&amp;gt;&lt;br /&gt;		&amp;lt;/property&amp;gt;&lt;br /&gt;	&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;	&amp;lt;bean id=&amp;#34;mydsSessionFactory&amp;#34;&lt;br /&gt;		class=&amp;#34;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&amp;#34;&amp;gt;&lt;br /&gt;		&amp;lt;property name=&amp;#34;namingStrategy&amp;#34;&amp;gt;&lt;br /&gt;			&amp;lt;ref bean=&amp;#34;mydsNamingStrategy&amp;#34; /&amp;gt;&lt;br /&gt;		&amp;lt;/property&amp;gt;&lt;br /&gt;		&amp;lt;property name=&amp;#34;annotatedClasses&amp;#34;&amp;gt;&lt;br /&gt;			&amp;lt;list&amp;gt;&lt;br /&gt;				&amp;lt;value&amp;gt;it.myds.datalayer.domainmodel.DSUser&amp;lt;/value&amp;gt;&lt;br /&gt;				.... other annotated classes....&lt;br /&gt;			&amp;lt;/list&amp;gt;&lt;br /&gt;		&amp;lt;/property&amp;gt;&lt;br /&gt;		&amp;lt;property name=&amp;#34;hibernateProperties&amp;#34;&amp;gt;&lt;br /&gt;			&amp;lt;props&amp;gt;&lt;br /&gt;				&amp;lt;prop key=&amp;#34;hibernate.dialect&amp;#34;&amp;gt;org.hibernate.dialect.PostgreSQLDialect&amp;lt;/prop&amp;gt;&lt;br /&gt;				&amp;lt;prop key=&amp;#34;hibernate.show_sql&amp;#34;&amp;gt;true&amp;lt;/prop&amp;gt;&lt;br /&gt;				&amp;lt;prop key=&amp;#34;hibernate.hbm2ddl.auto&amp;#34;&amp;gt;create&amp;lt;/prop&amp;gt;&lt;br /&gt;			&amp;lt;/props&amp;gt;&lt;br /&gt;		&amp;lt;/property&amp;gt;&lt;br /&gt;		&amp;lt;property name=&amp;#34;dataSource&amp;#34;&amp;gt;&lt;br /&gt;			&amp;lt;ref bean=&amp;#34;mydsDataSource&amp;#34; /&amp;gt;&lt;br /&gt;		&amp;lt;/property&amp;gt;&lt;br /&gt;	&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;I&amp;#39;ve put data model POJOs (those in ns &amp;#34;it.myds.datalayer.domainmodel.*&amp;#34;) in ext-services/src.&lt;br /&gt;I&amp;#39;ve also added some libraries to ext-lib/development:&lt;br /&gt;• /ext/ext-lib/development/commons-lang-2.4.jar&lt;br /&gt;• /ext/ext-lib/development/ejb3-persistence.jar&lt;br /&gt;• /ext/ext-lib/development/hibernate-annotations.jar&lt;br /&gt;• /ext/ext-lib/development/hibernate-core.jar&lt;br /&gt;• /ext/ext-lib/development/hibernate-entitymanager.jar&lt;br /&gt;• /ext/ext-lib/development/hibernate-validator.jar&lt;br /&gt;&lt;br /&gt;I&amp;#39;ve build and redeployed ext and all went successfully at compile time.&lt;br /&gt;(As a side note, do i&amp;#39;ll need to put (eventually some of) these libs also in global or portal dirs to be accessed at runtime?)&lt;br /&gt;&lt;br /&gt;Now before integrating DAOs, i would like to obtain &amp;#34;mydsSessionFactory&amp;#34; bean from a portlet to test the access to the new datasource. How i can refer to those beans from the portlet context? &lt;br /&gt;&lt;br /&gt;The fact is that my data layer uses annotations to define a quite complex schema. This is the reason i choosed integration  instead of migrating it towards service builder. &lt;br /&gt;Is this the right way to proceed in order to add a pre-existing datalayer based on Hibernate annotations, not using Service Builder ?&lt;br /&gt;&lt;br /&gt;Please, can you also comment on what i&amp;#39;m doing so if there is something done wrong i can restart doing things in right way ?&lt;br /&gt;&lt;br /&gt;Sorry for such long mail but i wasn&amp;#39;t able to find answers around.&lt;br /&gt;&lt;br /&gt;Thank you all,&lt;br /&gt;Luca</summary>
    <dc:creator>Luca Bernard</dc:creator>
    <dc:date>2009-11-02T10:35:25Z</dc:date>
  </entry>
</feed>
