Boa tarde galera, a pouco me deparei com um problema no qual não consigo achar a solução. É o seguinte tenho 2 classes no banco criadas através da anotations utilizando JPA. No entanto não consigo criar uma terceira tabela. Abaixo encontra-se a classe das duas tabelas existentes, e a classe a qual não consigo criar a tabela. Ao colocar a tag @Entity e @id da tabela o programa em si não executa.
Classe Clients que gera a tabela clients no BD
package model;
import javax.persistence.*;
import commons.SingleTon;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
@Entity
@Table (name="clients")
public class Client extends Model{
//Java Proprierties Headers
public static String NAME = "name";
public static String ADRESS = "adress";
public static String MAIL = "mail";
public static String PHONE = "phone";
public static String GENDER = "genderProperty";
public static String TYPE = "typeProperty";
public static String ID = "id";
@Id
@GeneratedValue
@Column (name="codCli")
public int getId() {
return id.get();
}
public void setId(int id2) {
id.set(id2);
}
public SimpleIntegerProperty idProperty(){
return id;
}
public enum ClientHeader{
cod("Codigo"),name("Nome"),adress("Endereco"),mail("Mail"),phone("Phone");
String con;
private ClientHeader(String con){
this.con = con;
}
public String toString(){
return con;
}
}
protected SimpleStringProperty name = new SimpleStringProperty();
protected SimpleStringProperty adress = new SimpleStringProperty();
protected SimpleStringProperty mail = new SimpleStringProperty();
protected SimpleStringProperty phone = new SimpleStringProperty();
protected SimpleStringProperty genderProperty = new SimpleStringProperty();
protected SimpleStringProperty typeProperty = new SimpleStringProperty();
protected SimpleIntegerProperty id = new SimpleIntegerProperty();
private boolean hasComanda = false;
public Client(int id2) {
this.id = new SimpleIntegerProperty(this, ID, id2);
}
public Client(){}
public Client(String name) {
super();
this.name = new SimpleStringProperty(this, NAME, name);
adress = new SimpleStringProperty(this, ADRESS);
mail = new SimpleStringProperty(this, MAIL);
phone = new SimpleStringProperty(this, PHONE);
this.genderProperty= new SimpleStringProperty(this, GENDER, "Masculino");
this.typeProperty = new SimpleStringProperty(this, TYPE, "Cliente");
}
public Client(String name, String adress) {
this(name);
this.adress = new SimpleStringProperty(this, ADRESS, adress);
}
public Client(String name, String adress, String mail) {
this(name, adress);
this.mail = new SimpleStringProperty(this, MAIL, mail);
}
public Client(String name, String adress, String mail, String phone) {
this(name, adress, mail);
this.phone = new SimpleStringProperty(this, PHONE, phone);
}
public Client(String name, String adress, String mail, String phone
, String gender) {
this(name, adress, mail);
this.phone = new SimpleStringProperty(this, PHONE, phone);
genderProperty = new SimpleStringProperty(this, GENDER, gender);
}
public Client(String name, String adress, String mail, String phone
, String gender, String type) {
this(name, adress, mail, phone, gender);
typeProperty = new SimpleStringProperty(this, TYPE, type);
}
public SimpleStringProperty nameProperty(){
return name;
}
public SimpleStringProperty adressProperty(){
return adress;
}
public SimpleStringProperty mailProperty(){
return mail;
}
public SimpleStringProperty phoneProperty(){
return phone;
}
public SimpleStringProperty genderProperty(){
return genderProperty;
}
public SimpleStringProperty typeProperty(){
return typeProperty;
}
@Column (name="nameCli", length=40)
public String getName() {
return name.get();
}
@Column (name="addressCli", length=70)
public String getAdress() {
return adress.get();
}
@Column (name="mailCli", length=50)
public String getMail() {
return mail.get();
}
@Column (name="phoneCli", length=25)
public String getPhone() {
return phone.get();
}
@Column (name="genderCli", length=20)
public String getGenderProperty(){
return genderProperty.get();
}
@Column (name="typeCli", length=20)
public String getTypeProperty(){
return typeProperty.get();
}
public void setGenderProperty(String a){
genderProperty.set(a);
}
public void setTypeProperty(String a){
typeProperty.set(a);
}
public static final class Types
{
public static final ObservableList<String> getTypes(){
ObservableList<String> types = FXCollections.observableArrayList();
types.add("Cliente");
types.add("Fornecedor");
return types;
}
}
public static final class Genders
{
public static final ObservableList<String> getGenders(){
ObservableList<String> gender = FXCollections.observableArrayList();
gender.add("Masculino");
gender.add("Feminino");
return gender;
}
}
public void setAdress(String adress) {
if (this.adress != null){
this.adress.set(adress);
}
}
public void setMail(String mail) {
this.mail.set(mail);
}
public void setName(String name) {
this.name.set(name);
}
public void setPhone(String phone) {
this.phone.set(phone);
}
void setComanda(boolean comanda){
hasComanda = comanda;
}
public boolean hasComanda(){
return hasComanda;
}
@Override
public String toString() {
return (getName());
}
@Override
public void save() {
/*
EntityManager manager = SingleTon.getInstance().createEntityManager();
manager.persist(this);
manager.getTransaction().begin();
manager.getTransaction().commit();
manager.close();
*/
}
@Override
public void delete() {
/*// TODO Auto-generated method stub
EntityManager manager = SingleTon.getInstance().createEntityManager();
Client c = manager.getReference(Client.class, this.getId());
manager.remove(c);
manager.getTransaction().begin();
manager.getTransaction().commit();
manager.close();
*/
}
@Override
public void update() {
// TODO Auto-generated method stub
}
public void updated(Client p) {
/*
EntityManager manager = SingleTon.getInstance().createEntityManager();
Client p2 = manager.merge(p);
p2 = this;
manager.getTransaction().begin();
manager.getTransaction().commit();
manager.close();
*/
}
}
Classe Users que gera a tabela users no banco
package model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import commons.Password;
import commons.SingleTon;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
@Entity
@Table (name="users")
public class User extends Model{
//Java Proprierties Headers
public static String NAME = "name";
public static String NIVEL = "nivel";
public static String PASSWORD = "pass";
public static String TIP = "tip";
public static String ID = "id";
protected SimpleStringProperty name = new SimpleStringProperty();
protected SimpleStringProperty nivel = new SimpleStringProperty();
protected SimpleStringProperty pass = new SimpleStringProperty();
protected SimpleStringProperty tip = new SimpleStringProperty();
protected SimpleIntegerProperty id = new SimpleIntegerProperty();
@Id
@GeneratedValue
@Column (name="codUser", length=11)
public int getId() {
// TODO Auto-generated method stub
return id.get();
}
public void setId(int a)
{
this.id.set(a);
}
public SimpleIntegerProperty idProperty(){
return id;
}
public User(){
id = new SimpleIntegerProperty(this, ID);
this.name = new SimpleStringProperty(this, NAME);
pass = new SimpleStringProperty(this, PASSWORD);
nivel = new SimpleStringProperty(this, NIVEL);
}
public User(int id2)
{
this.id = new SimpleIntegerProperty(this, ID, id2);
}
public User(String name) {
super();
this.name = new SimpleStringProperty(this, NAME, name);
//pass = new SimpleStringProperty(this, PASSWORD, Password.toHash("1234"));
pass = new SimpleStringProperty(this, PASSWORD, "123213");
nivel = new SimpleStringProperty(this, NIVEL, "Gerente");
this.tip = new SimpleStringProperty(this, TIP, "1234");
}
public User(String name, String nivel) {
this(name);
this.nivel = new SimpleStringProperty(this, NIVEL, nivel);
}
public User(String name, String nivel, String pass) {
this(name, nivel);
//this.pass = new SimpleStringProperty(this, PASSWORD, Password.toHash(pass));
this.pass = new SimpleStringProperty(this, PASSWORD, pass);
}
public User(String name, String nivel, String pass, String tip){
this(name,nivel,pass);
this.tip = new SimpleStringProperty(this, TIP, tip);
}
public SimpleStringProperty nameProperty(){
return name;
}
public SimpleStringProperty niveleProperty(){
return nivel;
}
public SimpleStringProperty passProperty(){
return pass;
}
public SimpleStringProperty tipProperty(){
return tip;
}
@Column (name="nameUser", length=25)
public String getName() {
return name.get();
}
@Column (name="passUser", length=255)
public String getPass()
{
return pass.get();
}
@Column (name="nivelUser", length=25)
public String getNivel()
{
return nivel.get();
}
@Column (name="tipUser", length=25)
public String getTip(){
return tip.get();
}
public void setName(String name)
{
this.name.set(name);
}
public void setPass(String pass)
{
this.pass.set(pass);
}
public void setNivel(String nivel)
{
this.nivel.set(nivel);
}
public void setTip(String tip){
this.tip.set(tip);
}
@Override
public void save() {
// TODO Auto-generated method stub
EntityManager manager = SingleTon.getInstance().createEntityManager();
manager.persist(this);
manager.getTransaction().begin();
manager.getTransaction().commit();
manager.close();
}
@Override
public void delete() {
// TODO Auto-generated method stub
EntityManager manager = SingleTon.getInstance().createEntityManager();
User c = manager.getReference(User.class, this.getId());
manager.remove(c);
manager.getTransaction().begin();
manager.getTransaction().commit();
manager.close();
}
public void update(User p) {
// TODO Auto-generated method stub
EntityManager manager = SingleTon.getInstance().createEntityManager();
User p2 = manager.merge(p);
p2 = this;
manager.getTransaction().begin();
manager.getTransaction().commit();
manager.close();
}
@Override
public void update() {
// TODO Auto-generated method stub
}
}
Classe UserCategory, a qual por algum motivo não consigo gerar no banco. Após o código encontra-se o logcat da execução da aplicação com o erro. Apenas colocando a anotation @Entity e @Id o erro já é gerado.
package model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javafx.beans.property.SimpleStringProperty;
public class UserCategory extends Model{
//Java Proprierties Headers
public static String NAME = "name";
public static String LEVEL = "level";
public int getId() {
// TODO Auto-generated method stub
return super.getId();
}
public enum UserCategoryHeader{
id("Codigo"),name("Nome"),level("Nivel");
String con;
private UserCategoryHeader(String con){
this.con = con;
}
@Override
public String toString(){
return con;
}
}
protected SimpleStringProperty name;
protected SimpleStringProperty level;
public UserCategory(){
this.name = new SimpleStringProperty(this, NAME);
this.level = new SimpleStringProperty(this, LEVEL);
}
public UserCategory(int id2) {
super(id2);
}
public UserCategory(String name) {
super();
this.name = new SimpleStringProperty(this, NAME, name);
}
public UserCategory(String name, String level) {
this(name);
this.level = new SimpleStringProperty(this, LEVEL, level);
}
public SimpleStringProperty nameProperty(){
return name;
}
public SimpleStringProperty levelProperty(){
return level;
}
public String getName() {
return name.get();
}
public String getLevel() {
return level.get();
}
public void setName(String name) {
this.name.set(name);
}
public void setAdress(String adress) {
this.level.set(adress);
}
@Override
public String toString() {
return ("\nId: " + getId() + " Name: " + getName() + " ");
}
@Override
public void save() {
// sql de insert no bd
}
@Override
public void delete() {
// TODO Auto-generated method stub
}
@Override
public void update() {
// TODO Auto-generated method stub
}
}
Persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="casa" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/casadochopp" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.use_sql_comments" value="false" />
<property name="hibernate.jdbc.wrap_result_sets" value="false" />
<property name="hibernate.hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
LOG do sistema em funcionamento sem a tentativa da edição da classe UserCategory
set 10, 2014 3:39:26 PM org.hibernate.ejb.HibernatePersistence logDeprecation WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead. set 10, 2014 3:39:26 PM org.hibernate.ejb.HibernatePersistence logDeprecation WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead. set 10, 2014 3:39:26 PM org.hibernate.ejb.HibernatePersistence logDeprecation WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead. set 10, 2014 3:39:26 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation INFO: HHH000204: Processing PersistenceUnitInfo [ name: casa ...] set 10, 2014 3:39:26 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.3.6.Final} set 10, 2014 3:39:26 PM org.hibernate.cfg.Environment INFO: HHH000206: hibernate.properties not found set 10, 2014 3:39:26 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist set 10, 2014 3:39:26 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final} set 10, 2014 3:39:26 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) set 10, 2014 3:39:26 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/casadochopp] set 10, 2014 3:39:26 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000046: Connection properties: {user=root, password=****} set 10, 2014 3:39:26 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000006: Autocommit mode: false set 10, 2014 3:39:26 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 (min=1) set 10, 2014 3:39:27 PM org.hibernate.dialect.Dialect INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect set 10, 2014 3:39:27 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory INFO: HHH000397: Using ASTQueryTranslatorFactory set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000228: Running hbm2ddl schema update set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000102: Fetching database metadata set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000396: Updating schema set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000261: Table found: casadochopp.clients set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000037: Columns: [typecli, phonecli, codcli, addresscli, namecli, gendercli, mailcli] set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000108: Foreign keys: [] set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000126: Indexes: [primary] set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000261: Table found: casadochopp.users set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000037: Columns: [nameuser, passuser, tipuser, coduser, niveluser] set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000108: Foreign keys: [] set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000126: Indexes: [primary] set 10, 2014 3:39:28 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000232: Schema update complete
Agora, a classe UserCategory editada, na tentativa de adicionar a tabela ao banco
package model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
@Entity
public class UserCategory extends Model{
//Java Proprierties Headers
public static String NAME = "name";
public static String LEVEL = "level";
public static String ID = "id";
@Id
@GeneratedValue
public int getId() {
return this.id.get();
}
public void setId(int d) {
// TODO Auto-generated method stub
this.id.set(d);
}
public SimpleIntegerProperty idProperty(){
return id;
}
public enum UserCategoryHeader{
id("Codigo"),name("Nome"),level("Nivel");
String con;
private UserCategoryHeader(String con){
this.con = con;
}
@Override
public String toString(){
return con;
}
}
protected SimpleStringProperty name = new SimpleStringProperty(this, NAME);
protected SimpleStringProperty level = new SimpleStringProperty(this, LEVEL);
protected SimpleIntegerProperty id = new SimpleIntegerProperty(this, ID);
public UserCategory(){}
public UserCategory(int id2) {
this.id = new SimpleIntegerProperty(this, ID);
}
public UserCategory(String name) {
super();
this.name = new SimpleStringProperty(this, NAME, name);
}
public UserCategory(String name, String level) {
this(name);
this.level = new SimpleStringProperty(this, LEVEL, level);
}
public SimpleStringProperty nameProperty(){
return name;
}
public SimpleStringProperty levelProperty(){
return level;
}
public String getName() {
return name.get();
}
public String getLevel() {
return level.get();
}
public void setName(String name) {
this.name.set(name);
}
public void setAdress(String adress) {
this.level.set(adress);
}
@Override
public String toString() {
return ("\nId: " + getId() + " Name: " + getName() + " ");
}
@Override
public void save() {
// sql de insert no bd
}
@Override
public void delete() {
// TODO Auto-generated method stub
}
@Override
public void update() {
// TODO Auto-generated method stub
}
}
LOG após a edição da classe e tentativa de compilação
set 10, 2014 3:36:54 PM org.hibernate.ejb.HibernatePersistence logDeprecation WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead. set 10, 2014 3:36:54 PM org.hibernate.ejb.HibernatePersistence logDeprecation WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead. set 10, 2014 3:36:54 PM org.hibernate.ejb.HibernatePersistence logDeprecation WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead. set 10, 2014 3:36:54 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation INFO: HHH000204: Processing PersistenceUnitInfo [ name: casa ...] set 10, 2014 3:36:54 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.3.6.Final} set 10, 2014 3:36:54 PM org.hibernate.cfg.Environment INFO: HHH000206: hibernate.properties not found set 10, 2014 3:36:54 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist set 10, 2014 3:36:55 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final} set 10, 2014 3:36:55 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) set 10, 2014 3:36:55 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/casadochopp] set 10, 2014 3:36:55 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000046: Connection properties: {user=root, password=****} set 10, 2014 3:36:55 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000006: Autocommit mode: false set 10, 2014 3:36:55 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 (min=1) set 10, 2014 3:36:55 PM org.hibernate.dialect.Dialect INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect set 10, 2014 3:36:55 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory INFO: HHH000397: Using ASTQueryTranslatorFactory Exception in Application start method
Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.