<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/testproj</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.username">alexroot</property>
<property name="hibernate.connection.pool_size">20</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL94Dialect</property>
<property name="show_sql">true</property>
<!--<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>-->
<property name="current_session_context_class">thread</property>
<property name="hibernate.connection.CharSet">utf8</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping package="pon.al.com"/>
<mapping class="pon.al.com.Role"/>
</session-factory>
@Entity
@Table(name ="role", uniqueConstraints = {@UniqueConstraint(columnNames = "ID")}, schema = "testproj")
public class Role implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "role_seq")
@SequenceGenerator(name = "role_seq", sequenceName = "SEQ_ROLE", allocationSize = 1, schema = "testproj")
@Column(name = "ID", nullable = false, updatable = false)
private Integer idRole;
@Column(name = "role_name", unique = false, nullable = false)
private String role;
public Role(){}
}
public class HibernateUtil {
private static SessionFactory sessionFactory = buildSessionFactory();
private static StandardServiceRegistry serviceRegistry;
public static SessionFactory buildSessionFactory(){
serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
try {
sessionFactory = new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();
}catch (HibernateException e){
e.printStackTrace();
System.out.println("Error creating session" + e);
throw new ExceptionInInitializerError(e);
}
return sessionFactory;
}
public static void shutdown() {
// Close caches and connection pools
if(sessionFactory != null){
sessionFactory.close();
}
if(serviceRegistry != null){StandardServiceRegistryBuilder.destroy(serviceRegistry);}
}
}
cofigure file hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/testproj</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.username">alexroot</property>
<property name="hibernate.connection.pool_size">20</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL94Dialect</property>
<property name="show_sql">true</property>
<!--<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>-->
<property name="current_session_context_class">thread</property>
<property name="hibernate.connection.CharSet">utf8</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping package="pon.al.com"/>
<mapping class="pon.al.com.Role"/>
</session-factory>
public static void main(String[] args) {
SessionFactory sessionFactory =
HibernateUtil.buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Role hr = new Role();
hr.setRole("hr");
session.save(hr);
session.beginTransaction().commit();
}catch (Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
session.beginTransaction().rollback();
}finally {
HibernateUtil.shutdown();
System.out.println("after");
}
}
мар 21, 2018 4:38:48 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.0.10.Final}
мар 21, 2018 4:38:48 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
мар 21, 2018 4:38:48 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
мар 21, 2018 4:38:48 PM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
мар 21, 2018 4:38:48 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
мар 21, 2018 4:38:48 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
мар 21, 2018 4:38:48 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/testproj]
мар 21, 2018 4:38:48 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {useUnicode=true, user=alexroot, password=****, CharSet=utf8, characterEncoding=utf8}
мар 21, 2018 4:38:48 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
мар 21, 2018 4:38:48 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
мар 21, 2018 4:38:48 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL94Dialect
мар 21, 2018 4:38:49 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
мар 21, 2018 4:38:49 PM org.hibernate.type.BasicTypeRegistry register
INFO: HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@7c1e2a9e
мар 21, 2018 4:38:49 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
мар 21, 2018 4:38:50 PM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
мар 21, 2018 4:38:50 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
мар 21, 2018 4:38:50 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/testproj]
мар 21, 2018 4:38:50 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {useUnicode=true, user=alexroot, password=****, CharSet=utf8, characterEncoding=utf8}
мар 21, 2018 4:38:50 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
мар 21, 2018 4:38:50 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
мар 21, 2018 4:38:50 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL94Dialect
мар 21, 2018 4:38:50 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
мар 21, 2018 4:38:50 PM org.hibernate.type.BasicTypeRegistry register
INFO: HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@7c1e2a9e
мар 21, 2018 4:38:50 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
Hibernate: select nextval ('testproj.SEQ_ROLE')
Hibernate: insert into testproj.role (role_name, ID) values (?, ?)
after
мар 21, 2018 4:38:50 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:postgresql://localhost:5432/testproj]
// Это появляется после того как я руками стопаю программу.
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:1.2.1.Final:deploy (default-cli) on project WebSiteGame: Failed to execute goal deploy.: java.net.ConnectException: WFLYPRT0053: Could not connect to remote+http://localhost:8080. The connection failed: В соединении отказано -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
<jsp:include page="../../head/head.jsp"/>
но я бы хотел разобраться почему не работает в первом примере.