Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version='1.0' encoding='utf-8'?>
- <!DOCTYPE hibernate-configuration SYSTEM "hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <!-- Database connection settings -->
- <property name="connection.driver_class">org.postgresql.Driver</property>
- <property name="connection.url">jdbc:postgresql://localhost/5432/hibernatedb</property>
- <property name="connection.username">postgres</property>
- <property name="connection.password">password</property>
- <!-- JDBC connection pool (use the built-in) -->
- <property name="connection.pool_size">1</property>
- <!-- SQL dialect -->
- <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
- <!-- Enable Hibernate's automatic session context management -->
- <property name="current_session_context_class">thread</property>
- <!-- Disable the second-level cache
- <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property> -->
- <!-- Echo all executed SQL to stdout -->
- <property name="show_sql">true</property>
- <!-- Drop and re-create the database schema on startup -->
- <property name="hbm2ddl.auto">create</property>
- <mapping class="org.javabrains.koushik.dto.UserDetails" />
- <!-- <mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/> -->
- </session-factory>
- </hibernate-configuration>
- package org.javabrains.koushik.dto;
- import javax.persistence.Entity;
- import javax.persistence.Id;
- @Entity
- public class UserDetails {
- @Id
- private int userID;
- private String userName;
- public int getUserID() {
- return userID;
- }
- public void setUserID(int userID) {
- this.userID = userID;
- }
- public String getUserName() {
- return userName;
- }
- public void setUserName(String userName) {
- this.userName = userName;
- }
- }
- package org.koushik.hibernate;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.cfg.AnnotationConfiguration;
- import org.javabrains.koushik.dto.UserDetails;
- public class HibernateTest {
- public static void main(String[] args) {
- UserDetails user = new UserDetails();
- user.setUserID(1);
- user.setUserName("First user");
- SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
- Session session =sessionFactory.openSession();
- session.beginTransaction();
- session.save(user);
- session.getTransaction().commit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement