Olá… estou tentando criar uma tabela e inserir dados pelo hibertante… ativei o log e quando crio o a tabela aparece isto no log:
drop table if exists Produto
09:39:31,171 DEBUG SchemaExport:303 - drop table if exists Produto
09:39:31,187 DEBUG JDBCExceptionReporter:40 - SQL Warning
java.sql.SQLWarning: Unknown table ‘produto’
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWarnings(SQLError.java:770)
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWarnings(SQLError.java:698)
at com.mysql.jdbc.StatementImpl.getWarnings(StatementImpl.java:2240)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:309)
at org.hibernate.tool.hbm2ddl.SchemaExport.drop(SchemaExport.java:284)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:186)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
at br.com.caelum.hibernate.GeraTabelas.main(GeraTabelas.java:15)
09:39:31,203 WARN JDBCExceptionReporter:48 - SQL Warning: 1051, SQLState: 42S02
09:39:31,203 WARN JDBCExceptionReporter:49 - Unknown table ‘produto’
create table Produto (id bigint not null auto_increment, nome varchar(255), descricao varchar(255), preco double precision, primary key (id))
09:39:31,203 DEBUG SchemaExport:303 - create table Produto (id bigint not null auto_increment, nome varchar(255), descricao varchar(255), preco double precision, primary key (id))
09:39:31,328 DEBUG JDBCExceptionReporter:40 - SQL Warning
java.sql.SQLWarning: Unknown table ‘produto’
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWarnings(SQLError.java:770)
at com.mysql.jdbc.SQLError.convertShowWarningsToSQLWarnings(SQLError.java:698)
at com.mysql.jdbc.StatementImpl.getWarnings(StatementImpl.java:2240)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:309)
at org.hibernate.tool.hbm2ddl.SchemaExport.drop(SchemaExport.java:284)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:186)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
at br.com.caelum.hibernate.GeraTabelas.main(GeraTabelas.java:15)
09:39:31,328 WARN JDBCExceptionReporter:48 - SQL Warning: 1051, SQLState: 42S02
09:39:31,328 WARN JDBCExceptionReporter:49 - Unknown table ‘produto’
09:39:31,328 INFO SchemaExport:196 - schema export complete
09:39:31,328 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
09:39:31,328 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:mysql://localhost/test
Mas ele cria a tabela… só nao sei pq dessas exceptions…
codigo p/ criar:
[code]public class GeraTabelas {
public static void main(String[] args) {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass(Produto.class);
SchemaExport schema = new SchemaExport(cfg);
schema.create(true, true);
}
}[/code]
ate ai tudo bem… mas ele nao está inserindo dados!
codigo p/ inserir:
[code]
public class AdicionaProduto {
public static void main(String[] args) {
Session session = new HibernateUtil().getSession();
Produto produto = new Produto();
produto.setNome("prod");
produto.setDescricao("desc");
produto.setPreco(100.50);
session.save(produto);
System.out.println("Id do produto" + produto.getId());
session.close();
}
}[/code]
Este é um exercicio da caelum do fj-21… se alguem puder me ajudar fico grato!