Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MAIN
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package cviko4;
- import java.util.List;
- import javax.persistence.*;
- /**
- *
- * @author vsa
- */
- public class Cviko4 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("cviko4PU");
- EntityManager em = emf.createEntityManager();
- Query q = em.createNativeQuery("SELECT * FROM Osoba", Osoba.class);
- List<Osoba> zo = q.getResultList();
- em.getTransaction().begin();
- for(Osoba o: zo){
- System.out.println("Name: "+o.getMeno());
- }
- em.getTransaction().commit();
- em.close();
- }
- }
- //=========================
- //OSOBA:
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package cviko4;
- import java.util.Date;
- import javax.persistence.*;
- /**
- *
- * @author vsa
- */
- @Entity
- public class Osoba {
- @Id
- private String meno;
- @Temporal(javax.persistence.TemporalType.DATE)
- private Date narodenie;
- private double vaha;
- public String getMeno() {
- return meno;
- }
- public double getVaha() {
- return vaha;
- }
- public void setMeno(String meno) {
- this.meno = meno;
- }
- public void setVaha(double vaha) {
- this.vaha = vaha;
- }
- public Osoba(){}
- public Osoba(String meno, double vaha) {
- this.meno = meno;
- this.vaha = vaha;
- }
- }
- //=======================
- //XML:
- <?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="cviko4PU" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <properties>
- <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/sample"/>
- <property name="javax.persistence.jdbc.user" value="app"/>
- <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
- <property name="javax.persistence.jdbc.password" value="app"/>
- <property name="eclipselink.logging.level" value="FINE"/>
- <exclude-unlisted-classes>false</exclude-unlisted-classes>
- </properties>
- </persistence-unit>
- </persistence>
Advertisement
Add Comment
Please, Sign In to add comment