Results 1 to 2 of 2

Thread: Hibernate + JPA Configuration Troubles

  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Default Hibernate + JPA Configuration Troubles

    Hi,

    I'm fairly comfortable using Hibernate outside of Spring with Annotations. I personally prefer using annotations to map my POJOs (@Entity, @Id, etc.), but I just can't seem to figure out how to configure Hibernate/JPA.

    How do I have the Spring container recognize that I'm using JPA annotations to map my POJOs? The following is my data source and session factory bean in application.xml:

    Code:
            <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<property name="url" value="jdbc:mysql://localhost/_reviews" />
    		<property name="username" value="xxxx" />
    		<property name="password" value="xxxx" />
    	</bean>
    	
    	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="mappingResources">
    			<!-- No hbm.xml files. Just annotations. How do I configure it here? -->
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.show_sql">true</prop>
    				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    				<prop key="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
    				<prop key="current_session_context_class">thread</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="bookServiceDAO" class="com.springbookstore.data.BookServiceDAOImplementation">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>
    Finally, am I correct to assume that my DAO bean will be injected with the same Hibernate Session Factory object?

    I started programming about six months ago, so I'm still a little shaky on using documentations to solve all of my problems. As such, if you could point to a place where I could have found a solution to this particular problem, I would greatly appreciate it.

    Thank you so much for your help.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    You want to use annotations thus use the AnnotationSessionFactoryBean. Next Don't mess around with the transaction.factory_class and current_session_context_class (unless you use JTA!).

    I also suggest a read of the reference guide especially the hibernate section it is pretty clear and consise.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •