Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication11;
- import java.io.Serializable;
- import java.util.Objects;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.Table;
- /**
- *
- * @author kB
- */
- @Entity
- @Table(name="room")
- public class NewEntity implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- @Column(name = "room_id")
- private int id;
- @Column(name = "room_name")
- private String name;
- public NewEntity() {
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- @Override
- public int hashCode() {
- int hash = 5;
- hash = 29 * hash + this.id;
- hash = 29 * hash + Objects.hashCode(this.name);
- return hash;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final NewEntity other = (NewEntity) obj;
- if (this.id != other.id) {
- return false;
- }
- if (!Objects.equals(this.name, other.name)) {
- return false;
- }
- return true;
- }
- @Override
- public String toString() {
- return super.toString(); //To change body of generated methods, choose Tools | Templates.
- }
- }
- package javaapplication11;
- import javax.persistence.EntityManager;
- import javax.persistence.EntityManagerFactory;
- import javax.persistence.Persistence;
- /**
- *
- * @author kB
- */
- public class JavaApplication11 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("JavaApplication11PU");
- EntityManager em = emf.createEntityManager();
- em.getTransaction().begin();
- NewEntity x = new NewEntity();
- x.setName("anan");
- em.persist(x);
- em.getTransaction().commit();
- em.close();
- emf.close();
- }
- }
- <?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="JavaApplication11PU" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <class>javaapplication11.NewEntity</class>
- <properties>
- <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/felek"/>
- <property name="javax.persistence.jdbc.user" value="root"/>
- <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
- <property name="javax.persistence.jdbc.password" value=""/>
- <property name="javax.persistence.schema-generation.database.action" value="create"/>
- </properties>
- </persistence-unit>
- </persistence>
Add Comment
Please, Sign In to add comment