Configurando o persistence.xml pro MySQL

8 respostas
S

Estou acompanhando um tutorial aqui, que no caso utiliza o postgresql, só que eu estou utilizando o mysql como eu adapto esse persistence.xml para o mysql?

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="vraptor">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>br.com.k2studio.vraptor.entity.Grupo</class>
    <class>br.com.k2studio.vraptor.entity.Usuario</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/teste" />
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
            <property name="hibernate.connection.username" value="postgres" />
            <property name="hibernate.connection.password" value="postgres" />
        </properties>
     </persistence-unit>
</persistence>

8 Respostas

drsmachado

Por favor, não é, camarada?
Isso que eu chamo de preguiça…
Qualquer busca no google traz vários resultados…

guilherme.dio

Segue um xml que sempre uso:

<persistence version="2.0"
	xmlns="http://java.sun.com/xml/ns/persistence" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
	http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

	<!-- UNIDADE DE TESTES -->
	<persistence-unit name="test">
	
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<jar-file>${project.build.outputDirectory}</jar-file>
		
		<properties>
			<!-- DADOS CONEXAO -->
			<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
			<property name="hibernate.connection.username" value="myfinances" />
			<property name="hibernate.connection.password" value="sourcesphere" />
			<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/sourcesphere_myfinances" />
			<property name="hibernate.default_schema" value="sourcesphere_myfinances"/>
		
			<!-- CONFIGURACAO -->
			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
			<property name="hibernate.hbm2ddl.auto" value="update" />
			<property name="hibernate.show_sql" value="true" />
			<property name="hibernate.format_sql" value="true" />
			<property name="hibernate.archive.autodetection" value="class" />
			
			<!-- POOL -->
			<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>
S

drsmachado:
Por favor, não é, camarada?
Isso que eu chamo de preguiça…
Qualquer busca no google traz vários resultados…

não os resultados que procuro. obrigado de qualquer forma.

R

Porque nao sabe ou nao insiste em continuar procurando.

S
guilherme.dio:
Segue um xml que sempre uso:
<persistence version="2.0"
	xmlns="http://java.sun.com/xml/ns/persistence" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
	http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

	<!-- UNIDADE DE TESTES -->
	<persistence-unit name="test">
	
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<jar-file>${project.build.outputDirectory}</jar-file>
		
		<properties>
			<!-- DADOS CONEXAO -->
			<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
			<property name="hibernate.connection.username" value="myfinances" />
			<property name="hibernate.connection.password" value="sourcesphere" />
			<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/sourcesphere_myfinances" />
			<property name="hibernate.default_schema" value="sourcesphere_myfinances"/>
		
			<!-- CONFIGURACAO -->
			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
			<property name="hibernate.hbm2ddl.auto" value="update" />
			<property name="hibernate.show_sql" value="true" />
			<property name="hibernate.format_sql" value="true" />
			<property name="hibernate.archive.autodetection" value="class" />
			
			<!-- POOL -->
			<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>

obrigado!

Hebert_Coelho

Steam:
drsmachado:
Por favor, não é, camarada?
Isso que eu chamo de preguiça…
Qualquer busca no google traz vários resultados…

não os resultados que procuro. obrigado de qualquer forma.

Eu nunca sei de cabeça, e sempre pego no google.

Da proxima vez, pesquise por:
jpa mysql persistence.xml

Por esse tipo de pesquisa eu sempre encontrei qualquer banco de dados. =D

Hhaninha
Steam:
Estou acompanhando um tutorial aqui, que no caso utiliza o postgresql, só que eu estou utilizando o mysql como eu adapto esse persistence.xml para o mysql?
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="vraptor">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>br.com.k2studio.vraptor.entity.Grupo</class>
    <class>br.com.k2studio.vraptor.entity.Usuario</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/teste" />
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
            <property name="hibernate.connection.username" value="postgres" />
            <property name="hibernate.connection.password" value="postgres" />
        </properties>
     </persistence-unit>
</persistence>

Olhe esse link http://www.patternizando.com.br/2011/08/configuracao-persistence-xml-jpa-para-mysql-derby-h2-oracle-postgresql-sql-server-e-hsqldb-para-hibernate/

W

guilherme.dio

Obrigado, me ajudou o seu arquivo. Funcionou perfeitamente.

Criado 28 de janeiro de 2013
Ultima resposta 24 de set. de 2014
Respostas 8
Participantes 7