Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.com.etown.onetoone;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.OneToOne;
- @Entity
- public class UserDetails {
- @Id @GeneratedValue(strategy = GenerationType.AUTO)
- 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.com.etown.onetoone;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.cfg.Configuration;
- public class UserDatailsDao {
- public static void main(String[] args) {
- UserDetails user = new UserDetails();
- user.setUserName("george");
- SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
- Session session = sessionFactory.openSession();
- session.beginTransaction();
- session.save(user);
- session.getTransaction().commit();
- session.close();
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE hibernate-configuration SYSTEM
- "http://www.hibernate.org/dtd/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/etowndb</property>
- <property name="connection.username">postgres</property>
- <property name="connection.password">root</property>
- <!-- JDBC connection pool (use the built-in) -->
- <property name="connection.pool_size">1</property>
- <!-- SQL Dialect -->
- <property name="dialect">org.hibernate.dialect.PostgreSQL92Dialect</property>
- <!-- Disable the second level class -->
- <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
- <!-- Echo all executed SQL to stdout -->
- <property name="show_sql">true</property>
- <!-- Drop and re-creat the database schema on startup -->
- <property name="hbm2ddl.auto">update</property><!-- update,create -->
- <!-- Names of the annotated entity class -->
- <mapping class="org.com.etown.onetoone.UserDetails"/>
- </session-factory>
- </hibernate-configuration>
- Oct 13, 2016 12:46:30 PM org.hibernate.Version logVersion
- INFO: HHH000412: Hibernate Core {5.1.1.Final}
- Oct 13, 2016 12:46:30 PM org.hibernate.cfg.Environment <clinit>
- INFO: HHH000206: hibernate.properties not found
- Oct 13, 2016 12:46:30 PM org.hibernate.cfg.Environment buildBytecodeProvider
- INFO: HHH000021: Bytecode provider name : javassist
- Oct 13, 2016 12:46:30 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
- INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
- Oct 13, 2016 12:46:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
- WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
- Oct 13, 2016 12:46:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
- INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/etowndb]
- Oct 13, 2016 12:46:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
- INFO: HHH10001001: Connection properties: {user=postgres, password=****}
- Oct 13, 2016 12:46:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
- INFO: HHH10001003: Autocommit mode: false
- Oct 13, 2016 12:46:30 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
- INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
- Oct 13, 2016 12:46:30 PM org.hibernate.dialect.Dialect <init>
- INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL92Dialect
- Oct 13, 2016 12:46:31 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
- INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
- Oct 13, 2016 12:46:31 PM org.hibernate.type.BasicTypeRegistry register
- INFO: HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@7ffeac8e
- Oct 13, 2016 12:46:31 PM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
- INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@31c08b2e] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
- Oct 13, 2016 12:46:31 PM org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl processGetTableResults
- INFO: HHH000262: Table not found: UserDetails
- Oct 13, 2016 12:46:31 PM org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl processGetTableResults
- INFO: HHH000262: Table not found: UserDetails
- Hibernate: create table UserDetails (userid int4 not null, userName varchar(255), primary key (userid))
- Oct 13, 2016 12:46:31 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper$StandardWarningHandler logWarning
- WARN: SQL Warning Code: 0, SQLState: 00000
- Oct 13, 2016 12:46:31 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper$StandardWarningHandler logWarning
- WARN: CREATE TABLE / PRIMARY KEY will create implicit index "userdetails_pkey" for table "userdetails"
- Hibernate: select nextval ('hibernate_sequence')
- @GeneratedValue(strategy = GenerationType.AUTO)
- @GeneratedValue(strategy = GenerationType.IDENTITY)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement