livro.xhtml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<h1>Novo Livro</h1>
<h:form>
<h:messages />
<fieldset>
<legend>Dados do Livro</legend>
<h:panelGrid columns="2">
<h:outputLabel value="Titulo:" for="titulo" />
<h:inputText id="titulo" value="#{livroBean.livro.titulo}" />
<h:outputLabel value="ISBN:" for="isbn" />
<h:inputText id="isbn" value="#{livroBean.livro.isbn}" />
<h:outputLabel value="Preço:" for="preco" />
<h:inputText id="preco" value="#{livroBean.livro.preco}" />
<h:outputLabel value="Data de Lançamento:" for="dataLancamento" />
<h:inputText id="dataLancamento" value="#{livroBean.livro.dataLancamento.time}">
<f:convertDateTime pattern="dd/MM/yyyy" timeZone="America/Sao_Paulo" />
</h:inputText>
</h:panelGrid>
</fieldset>
<fieldset>
<legend>Dados do Autor</legend>
<h:outputLabel value="Selecione o Autor:" for="autor" />
<h:selectOneMenu value="#{livroBean.autorId}" id="autor">
<f:selectItems value="#{livroBean.autores}" var="autor"
itemLabel="#{autor.nome}" itemValue="#{autor.id}" />
</h:selectOneMenu>
<h:commandButton value="Gravar Autor"
action="#{livroBean.gravarAutor}" />
<h:dataTable value="#{livroBean.autoresDoLivro}" var="autor">
<h:column>
<h:outputText value="#{autor.nome}" />
</h:column>
</h:dataTable>
</fieldset>
<br />
<h:commandButton value="Gravar" action="#{livroBean.gravar}" />
<h2>Tabela de Livros cadastrados:</h2>
<h:dataTable id="tabelaLivros" value="#{livroBean.livros}" var="livro">
<h:column>
<f:facet name="header">Título</f:facet> |
<h:outputText value="#{livro.titulo}" />
</h:column>
<h:column>
<f:facet name="header">ISBN</f:facet> |
<h:outputText value="#{livro.isbn}" />
</h:column>
<h:column>
<f:facet name="header">Preço</f:facet> |
<h:outputText value="#{livro.preco}" />
</h:column>
<h:column>
<f:facet name="header">Data Lançamento</f:facet> |
<h:outputText value="#{livro.dataLancamento}" /> |
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>
No console, não gerou nenhum erro:
mar 30, 2016 11:21:45 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
mar 30, 2016 11:21:45 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.8.Final}
mar 30, 2016 11:21:45 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
mar 30, 2016 11:21:45 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
mar 30, 2016 11:21:46 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
mar 30, 2016 11:21:46 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
mar 30, 2016 11:21:46 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
mar 30, 2016 11:21:46 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/livrariadb]
mar 30, 2016 11:21:46 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****, autocommit=true, release_mode=auto}
mar 30, 2016 11:21:47 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
mar 30, 2016 11:21:47 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
mar 30, 2016 11:21:47 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
mar 30, 2016 11:21:48 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
mar 30, 2016 11:21:48 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
mar 30, 2016 11:21:48 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
mar 30, 2016 11:21:48 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: livrariadb.autor
mar 30, 2016 11:21:48 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [nome, id]
mar 30, 2016 11:21:48 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
mar 30, 2016 11:21:48 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary]
mar 30, 2016 11:21:48 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: livrariadb.livro
mar 30, 2016 11:21:48 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [preco, isbn, titulo, id, datalancamento]
mar 30, 2016 11:21:48 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
mar 30, 2016 11:21:48 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary]
mar 30, 2016 11:21:49 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: livrariadb.livro_autor
mar 30, 2016 11:21:49 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [livro_id, autores_id]
mar 30, 2016 11:21:49 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: [fk9590997ad70c7e4a, fk9590997afa17418]
mar 30, 2016 11:21:49 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [fk9590997afa17418, fk9590997ad70c7e4a]
mar 30, 2016 11:21:49 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
Hibernate: select autor0_.id as id1_, autor0_.nome as nome1_ from Autor autor0_
Hibernate: select autor0_.id as id1_, autor0_.nome as nome1_ from Autor autor0_
Hibernate: select livro0_.id as id0_, livro0_.dataLancamento as dataLanc2_0_, livro0_.isbn as isbn0_, livro0_.preco as preco0_, livro0_.titulo as titulo0_ from Livro livro0_
Hibernate: select livro0_.id as id0_, livro0_.dataLancamento as dataLanc2_0_, livro0_.isbn as isbn0_, livro0_.preco as preco0_, livro0_.titulo as titulo0_ from Livro livro0_
Hibernate: select livro0_.id as id0_, livro0_.dataLancamento as dataLanc2_0_, livro0_.isbn as isbn0_, livro0_.preco as preco0_, livro0_.titulo as titulo0_ from Livro livro0_
Hibernate: select livro0_.id as id0_, livro0_.dataLancamento as dataLanc2_0_, livro0_.isbn as isbn0_, livro0_.preco as preco0_, livro0_.titulo as titulo0_ from Livro livro0_
Hibernate: select livro0_.id as id0_, livro0_.dataLancamento as dataLanc2_0_, livro0_.isbn as isbn0_, livro0_.preco as preco0_, livro0_.titulo as titulo0_ from Livro livro0_
Hibernate: select livro0_.id as id0_, livro0_.dataLancamento as dataLanc2_0_, livro0_.isbn as isbn0_, livro0_.preco as preco0_, livro0_.titulo as titulo0_ from Livro livro0_