gscordeiro / faces-motors Goto Github PK
View Code? Open in Web Editor NEWCódigo fonte do Livro de JSF e JPA da Casa do Código
Código fonte do Livro de JSF e JPA da Casa do Código
Dá erro, dizendo que o ID é nulo, mas mesmo assim adiciona no banco.
Boa noite, realizando uma consulta simples na main após inserir o dado o mesmo da essa mensagem de erro: Lembrando que peguei a sua aplicação e copiei todos os jar dela e o persistence.xml.
Nov 11, 2012 9:15:45 PM org.hibernate.annotations.common.Version
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Nov 11, 2012 9:15:45 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.4.Final}
Nov 11, 2012 9:15:45 PM org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
Nov 11, 2012 9:15:45 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Nov 11, 2012 9:15:46 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Nov 11, 2012 9:15:46 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
Nov 11, 2012 9:15:46 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
Nov 11, 2012 9:15:46 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/automoveis]
Nov 11, 2012 9:15:46 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****, autocommit=true, release_mode=auto}
Nov 11, 2012 9:15:46 PM org.hibernate.dialect.Dialect
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Nov 11, 2012 9:15:46 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
Nov 11, 2012 9:15:46 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory
INFO: HHH000397: Using ASTQueryTranslatorFactory
Nov 11, 2012 9:15:46 PM org.hibernate.validator.internal.util.Version
INFO: HV000001: Hibernate Validator 4.3.0.Final
Nov 11, 2012 9:15:46 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
Nov 11, 2012 9:15:46 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
Nov 11, 2012 9:15:46 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
Nov 11, 2012 9:15:46 PM org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000261: Table found: automoveis.automovel
Nov 11, 2012 9:15:46 PM org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000037: Columns: [id, marca, observacoes, modelo, anofabricacao, anomodelo]
Nov 11, 2012 9:15:46 PM org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000108: Foreign keys: []
Nov 11, 2012 9:15:46 PM org.hibernate.tool.hbm2ddl.TableMetadata
INFO: HHH000126: Indexes: [primary]
Nov 11, 2012 9:15:46 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
Exception in thread "main" java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: automovel is not mapped [select a from automovel a]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1364)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:355)
at com.estudo.livro.jsfjpa.persistenciaTeste.PersistidorDeAutomovel.main(PersistidorDeAutomovel.java:18)
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: automovel is not mapped [select a from automovel a]
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:324)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3270)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3159)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:562)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:105)
at org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:80)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:219)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:197)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1736)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:301)
... 1 more
Se você tem apenas um modelo para uma marca do banco, não importando se existem outras marcas "faces/modelo/listar.xhtml" não funcionará.
Olá, estou praticamente no inicio dos passos de JPA. Na parte em que o persistense.xml já está configurado e tenta-se persistir os dados no banco através da classe PersistidorDeAutomovel.java. Porém ao tentar rodar recebo o seguinte erro:
190 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
203 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.7.Final
207 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
216 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
224 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
314 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.6.7.Final
Exception in thread "main" javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML (line-1 : column -1): cvc-elt.1: Não pode localizar a declaração do elemento 'persistence'.
at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:145)
at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:169)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:317)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at PersistidorDeAutomoveis.main(PersistidorDeAutomoveis.java:11)
Por que motivo o fechamento do EntityManager está comentado no OpenSessionAndTransactionInView?
// em.close(); (linha 44)
Tive problemas em relação às transações quando removi os comentários. Mas creio que o correto seria fechar o EntityManager.
Seguindo o exemplo do livro na hora que fui remover um registro, aconteceu o seguinte erro:
Removing a detached instance br.com.livro.jsfjpa.entidade.Automovel#4
Pesquisando na net falaram para eu modificar algumas coisas no código, mas acredito que seja alguma besteira que não haja necessidade de alterar o código. Segue meu método remover.
public void exclui(Automovel auto){
EntityManager em = JPAUtil.getEntityManager();
em.getTransaction().begin();
em.remove(auto);
em.getTransaction().commit();
em.close();
}
e o commandLink está dessa forma:
dentro do <h:form>
<h:column>
<f:facet name="header"> Ações /f:facet
<h:commandLink action="# {automovelBean.exclui(automovel)}">Excluir/h:commandLink
/h:column
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.