Boa tarde meus queridos amigos,
Estou com um problema simples, mas que ainda não consegui resolver… certamente devido a minha inexperiência com o framework Hibernate
Seguinte:
Tenho três tabelas em SqlServer:
Account
User
User_account
Preciso criar uma account, um user (ok, já tenho os beans) e preciso fazer esse relacionamento na tabela User_account. Preciso pegar o índice do account, do user e colocar no User_account.
Criei um bean para user_account também. Estou usando as Annotations do Hibernate, mas não consigo fazer esse relacionamento. Procurei no guj e não encontrei solução.
Vejam os códigos
Bean Account
[code]import java.math.BigDecimal;
import java.util.Calendar;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
@Entity
@GenericGenerator(
name=“geradorIdAccount”,
strategy=“geradores.GenerateID”)
@Table(name=“tbl_account”)
public class Account{
@Id @GeneratedValue(
generator="geradorIdAccount")
@OneToOne(fetch = FetchType.LAZY, cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE})
private Integer account_id;
private String account_type;
private String account_name;
private BigDecimal balance;
private Character restricted;
private Double overdraft;
private String pin;
private Character use_global_overdraft;
private String notes;
private Character deleted;
private Calendar deleted_date;
private Calendar created_date;
private String created_by;
private Calendar modified_date;
private String modified_by;
private Integer parent_id;
private String account_name_lower;
private String sub_name;
private String sub_name_lower;
private Character disabled;
private String disabled_until;
private String comments;
private String invoicing;
private String sub_pin;
//getters e setters
[/code]
Bean User
import java.util.Calendar;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
@Entity
@GenericGenerator(name="geradorIdUser",strategy="geradores.GenerateID")
@Table(name="tbl_user")
public class User {
@Id @GeneratedValue(generator="geradorIdUser")
private Integer user_id;
private String user_name;
private String external_user_name;
private String full_name;
private String email;
private String notes;
private Integer total_jobs;
private Integer total_pages;
private Integer total_sheets;
private String reset_by;
private Calendar reset_date;
private Character deleted;
private Calendar deleted_date;
private Calendar created_date;
private String created_by;
private Calendar modified_date;
private String modified_by;
private String department;
private String office;
private String card_number;
private Character disabled_printing;
private Calendar disabled_printing_until;
private String net_reset_by;
private String net_reset_date;
private Double net_total_megabytes;
private Double net_total_time_hours;
private Character disabled_net;
private Calendar disabled_net_until;
private Character internal;
private Calendar last_user_activity;
// getters e setters
Bean User_account
[code]@Entity
@GenericGenerator(
name=“geradorIdUserAccount”,
strategy=“geradores.GenerateID”)
@Table(name=“tbl_user_account”)
public class User_account {
@Id @GeneratedValue(
generator="geradorIdUserAccount")
private Integer user_account_id;
@Column(name="user_id")
private User user;
@OneToOne(fetch = FetchType.LAZY, cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE})
@Column(name="account_id")
private Account account;
private Calendar created_date;
private String created_by;
private Calendar modified_date;
private String modified_by;
//Getters e setter
[/code]
Percebam que não configurei nenhuma Annotation no bean User, estou tenstando ainda o Account.
Queridos, agradeço qualquer ajuda. Realmente estou vendo Hibernate agora.
Abraços