Created
September 24, 2014 19:41
-
-
Save blabadi/f1979814905efb502347 to your computer and use it in GitHub Desktop.
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
package com.blabadi.gradle.dao; | |
import com.blabadi.gradle.be.Person; | |
public interface PersonDao { | |
int addPerson(Person p); | |
} |
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
package com.blabadi.gradle.dao; | |
import org.hibernate.SessionFactory; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Component; | |
import com.blabadi.gradle.be.Person; | |
@Component | |
public class PersonDaoImpl implements PersonDao { | |
@Autowired | |
private SessionFactory sessionFactory; | |
@Override | |
public int addPerson(Person p) { | |
PersonDO pdo = new PersonDO(); | |
pdo.setId(p.getId()); | |
pdo.setName(p.getName()); | |
int id = (Integer) this.sessionFactory.getCurrentSession().save(pdo); | |
return 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
package com.blabadi.gradle.dao; | |
import javax.persistence.Column; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.Id; | |
import javax.persistence.Table; | |
@Entity | |
@Table(name = "Person") | |
public class PersonDO { | |
@Id @GeneratedValue | |
@Column(name = "id") | |
private int id; | |
@Column(name = "name") | |
private String name; | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment