Frage

I have Hibernate on my project,

but no Spring yet.

I wonder if:

Question 1:

Hibernate annotations and dialect propert in persistence.xml is enough for Hibernate to generate tables?

Question 2: Also i guess, there must be something like Spring to look for annotations and fire a generation event and start some other things?

EDIT:

My persistence.xml file

<?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="Kutuphane2" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>kutuphaneDS</non-jta-data-source>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/kutuphane"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="root"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.hbm2ddl.auto" value="create"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
        </properties>
    </persistence-unit>
</persistence>
War es hilfreich?

Lösung

Hibernate annotations and dialect propert in persistence.xml is enough for Hibernate to generate tables?

Yes, Hibernate works by itself, Spring just helps Hibernate to provide a data source and help you to access to the Hibernate API.

there must be something like Spring to look for annotations and fire a generation event and start some other things?

Nope, that's Hibernate work as well, just by adding hibernate.hbm2ddl.auto property. This is explained here:

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top