Boa tarde, colegas.
Estou implementando um exemplo bem simples, com hibernate.
Estou recebendo uma mensagem na exception: database product name cannot be null
Todos os arquivos estão em um pacote chamado ‘george’.
Perfil.java
public class Perfil {
Integer codigoPerfil;
String descricaoPerfil;
public Integer getCodigoPerfil() {
return codigoPerfil;
}
public void setCodigoPerfil(Integer codigoPerfil) {
this.codigoPerfil = codigoPerfil;
}
public String getDescricaoPerfil() {
return descricaoPerfil;
}
public void setDescricaoPerfil(String descricaoPerfil) {
this.descricaoPerfil = descricaoPerfil;
}
public Perfil(Integer codigoPerfil, String descricaoPerfil) {
super();
this.codigoPerfil = codigoPerfil;
this.descricaoPerfil = descricaoPerfil;
}
}
PerfilDAO.java
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class PerfilDAO {
private SessionFactory factory;
public PerfilDAO() throws Exception{
factory = new Configuration().addClass(Perfil.class).buildSessionFactory();
}
public void insert(Perfil perfil) throws Exception{
Session session = factory.openSession();
session.save(perfil);
session.flush();
session.close();
}
public static void main(String[] args) throws Exception {
new PerfilDAO().insert(new Perfil(50, "teste"));
}
}
Perfil.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Perfil" table="INT_PERFIS">
<id name="codigoPerfil" column="PER_CODIGO_PERFIL">
<generator class="increment"></generator>
</id>
<property name="descricaoPerfil" column="PER_DESCRICAO" />
</class>
</hibernate-mapping>
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@10.20.2.15:1521:gps</property>
<property name="connection.username">USER</property>
<property name="connection.password">SENHA</property>
</session-factory>
</hibernate-configuration>
Exception recebida:
Exception in thread "main" org.hibernate.HibernateException: database product name cannot be null
at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:374)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:110)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
at george.PerfilDAO.<init>(PerfilDAO.java:12)
at george.PerfilDAO.main(PerfilDAO.java:25)