Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- public class Apartamento implements Serializable {
- @EmbeddedId
- private Chave chave;
- private Long andar;
- private String descricao;
- private BigDecimal valor;
- private Long quantidade;
- //Contrutores, getts e settes //
- @Embeddable
- public class Chave implements Serializable{
- private Long id;
- private String ala;
- public Chave() {}
- public Chave(Long id, String ala) {
- this.id = id;
- this.ala = ala;
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public String getAla() {
- return ala;
- }
- public void setAla(String ala) {
- this.ala = ala;
- }
- }
- em.getTransaction().begin();
- Chave chave = new Chave(numero, ala);
- Apartamento ap = new Apartamento(chave, andar, descricao, valor, quantidade);
- em.persist(ap);
- em.getTransaction().commit();
- public EntityManager getEM(){
- emf = Persistence.createEntityManagerFactory("hotel");
- return emf.createEntityManager();
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
- http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
- <!-- unidade de persistencia com o nome financas -->
- <persistence-unit name="hotel">
- <!-- Implementação do JPA, no nosso caso Hibernate -->
- <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
- <!-- Aqui são listadas todas as entidades -->
- <class>entity.Apartamento</class>
- <class>entity.Contato</class>
- <class>entity.Hospede</class>
- <class>entity.Admin</class>
- <properties>
- <!-- Propriedades JDBC -->
- <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
- <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/test"/>
- <property name="javax.persistence.jdbc.user" value="root"/>
- <property name="javax.persistence.jdbc.password" value=""/>
- <!-- Configurações específicas do Hibernate -->
- <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
- <property name="hibernate.hbm2ddl.auto" value="update"/>
- <property name="hibernate.show_sql" value="true"/>
- <property name="hibernate.format_sql" value="true"/>
- </properties>
- java.lang.IllegalArgumentException: Provided id of the wrong type for class entity.Apartamento. Expected: class entity.Chave, got class java.lang.Long
Add Comment
Please, Sign In to add comment