Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <persistence>
- <persistence-unit name="miPersistenceUnit" transaction-type="RESOURCE_LOCAL">
- <class>stack.overflow.Respuesta</class>
- </persistence-unit>
- </persistence>
- //Inicialización factoría
- EntityManagerFactory emf;
- Map properties = new HashMap();
- properties.put("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");//Clase del driver a utilizar
- properties.put("hibernate.connection.url", "jdbc:mysql://localhost:3306/miBD");//URL de conexión a la BD
- properties.put("hibernate.connection.username", "root");//Usuario
- properties.put("hibernate.connection.password", "mysql");//Contraseña
- properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");//Dialecto hibernate
- properties.put("hibernate.show-sql", "true");
- emf = Persistence.createEntityManagerFactory("miPersistenceUnit",properties);
- //Creación EntityManager
- EntityManager entityManager = (EntityManager) emf.createEntityManager();
- //Insert ejemplo
- entityManager.getTransaction().begin();
- Respuesta miRespuesta = new Respuesta(1,"A ver si vale");
- entityManager.persist(miRespuesta);
- entityManager.getTransaction().commit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement