-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cnls
committed
Aug 23, 2017
1 parent
dbf4062
commit 3544944
Showing
5 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package entity; | ||
|
||
import java.io.Serializable; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class UserBasic extends User implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
private String lastName; | ||
|
||
public String getLastName() | ||
{ | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String lastName) | ||
{ | ||
this.lastName = lastName; | ||
} | ||
|
||
public Long getId() | ||
{ | ||
return id; | ||
} | ||
|
||
public void setId(Long id) | ||
{ | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
int hash = 0; | ||
hash += (id != null ? id.hashCode() : 0); | ||
return hash; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) | ||
{ | ||
// TODO: Warning - this method won't work in the case the id fields are not set | ||
if (!(object instanceof UserBasic)) | ||
{ | ||
return false; | ||
} | ||
UserBasic other = (UserBasic) object; | ||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "entity.UserBasic[ id=" + id + " ]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package jpacontrol; | ||
|
||
import entity.Address; | ||
import entity.Shoe; | ||
import entity.User; | ||
import entity.UserBasic; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.persistence.Persistence; | ||
|
||
public class Populate2 | ||
{ | ||
public static void main(String[] args) | ||
{ | ||
EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpaPU"); | ||
|
||
EntityManager em = emf.createEntityManager(); | ||
|
||
em.getTransaction().begin(); | ||
|
||
User u = new User(); | ||
u.setFirstName("William"); | ||
em.persist(u); | ||
u.setFirstName("George"); | ||
em.persist(u); | ||
|
||
User u1 = new User(); | ||
u1.setFirstName("John"); | ||
u1.setId(222l); | ||
em.merge(u1); | ||
u1.setFirstName("Jack"); | ||
em.merge(u1); | ||
|
||
User u2 = em.find(User.class, 222l); | ||
System.out.println("FUNDET: " + u2.getFirstName()); | ||
u2.setFirstName("NoName"); | ||
|
||
em.merge(u2); | ||
|
||
em.remove(u2); | ||
|
||
|
||
|
||
em.getTransaction().commit(); | ||
|
||
em.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters