0

I am on my way to configure hibernate. I have generated a persistance.xml file, which is configured the following.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
        <persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.archive.autodetection" value="class, hbm" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.format_sql" value="true" />

            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />

            <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" />
            <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:." />
            <property name="hibernate.connection.username" value="SA" />
            <property name="hibernate.connection.password" value="" />

            <property name="hibernate.c3p0.min_size" value="5" />
            <property name="hibernate.c3p0.max_size" value="20" />
            <property name="hibernate.c3p0.timeout" value="300" />
            <property name="hibernate.c3p0.max_statements" value="50" />
            <property name="hibernate.c3p0.idle_test_period" value="3000" />

        </properties>
    </persistence-unit>
</persistence>

Furthermore, I have added spring & hibernate to the pom.xml file. However, my test class, Register.java is not created in the data base:

@Entity
public class Register implements Serializable{

    /**
     * UUID
     */
    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    @Id
    @GeneratedValue
    private Long id;

    /**
     * user Email
     * 
     */
    @NotNull
    @Pattern(regexp = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$", message = "please enter your email address")
    @Column(name="user_email")
    private String userEmail;

    /**
     *first name
     */
    @NotNull
    @Pattern(regexp = "[A-Za-z ]*", message = "please enter your first name")
    @Column(name="first_Name")
    private String firstName;

    /**
     * last name
     */
    @NotNull
    @Pattern(regexp = "[A-Za-z ]*", message = "please enter your last name")
    @Column(name="last_Name")
    private String lastName;

    /**
     * Date when the product is created
     */
    @NotNull
    @Column(name="creation_date")
    private Date creationDate = new Date();

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the userEmail
     */
    public String getUserEmail() {
        return userEmail;
    }

    /**
     * @param userEmail the userEmail to set
     */
    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    /**
     * @return the firstName
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * @param firstName the firstName to set
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * @return the lastName
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * @param lastName the lastName to set
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * @return the creationDate
     */
    public Date getCreationDate() {
        return creationDate;
    }

    /**
     * @param creationDate the creationDate to set
     */
    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    /**
     * @return the serialversionuid
     */
    public static long getSerialversionuid() {
        return serialVersionUID;
    }

}

Furthermore, I am receiving the warning:

No connection specified for project. No database-specific validation

Any recommendations, what am I doing wrong?

UPDATE

The applicationContext.xml

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="
                        http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.0.xsd
                        http://www.springframework.org/schema/tx 
                        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                        http://www.springframework.org/schema/aop 
                        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                        http://www.springframework.org/schema/jee 
                        http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">

    <context:component-scan base-package="com.testApp" annotation-config="true" />

    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="default" />
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

</beans>
Carol.Kar
  • 4,581
  • 36
  • 131
  • 264
  • 1
    You need an Entity Manager Factory. Take a look at this: http://stackoverflow.com/questions/5373035/how-to-get-jpa-configured-with-spring-3 – Andres May 26 '14 at 14:51
  • @Andres Thx for your answer! Is it possible to let eclipse create the `applicationContext.xml` file or do I have to create it manually? Where would I have to create it? – Carol.Kar May 26 '14 at 14:54
  • Can you share with us your applicationContext.xml? – Skizzo May 26 '14 at 18:26
  • I had a similar problem with eclipseLink and you have to remember this "The tables should be created when the EntityManager is first deployed" anyway you can find some suggestion on this question [EclipseLink doesn't create tables](http://stackoverflow.com/questions/22964611/eclipselink-doesnt-create-tables) – Skizzo May 26 '14 at 18:32
  • @Skizzo pls have a look at my `applicationContext.xml` – Carol.Kar Jun 04 '14 at 12:05
  • @Andres Thx for pointing out the question. However, I have created everything you mentioned in the post. I appreciate your answer! – Carol.Kar Jun 04 '14 at 12:06
  • @Kare, could you tell us where's your current persistence.xml file located in your project? – Amir Jun 04 '14 at 12:10
  • @Kare Where is your datasource? You need to create a datasource bean and then do `` `` – geoand Jun 04 '14 at 12:12

0 Answers0