How to store following the entity using Hibernate?
@Entity
class A {
private Map<String, String> b;
// getters and setters omitted
}
How to store following the entity using Hibernate?
@Entity
class A {
private Map<String, String> b;
// getters and setters omitted
}
Have a look at @ElementCollection
Example usage:
@Entity
public class User {
public String getLastname() { ...}
@ElementCollection
@CollectionTable(name="Nicknames", joinColumns=@JoinColumn(name="user_id"))
@Column(name="nickname")
public Set<String> getNicknames() { ... }
}
Using Save
Here an example:
A variable = new A();
variable.b(your_variable);
Then
session.save(varible);
can be used. Or you mean to store in a database by the storage? Then will be so:
SessionFactory factory=cfg.buildSessionFactory();
Session session=factory.openSession();
Transaction t=session.beginTransaction();
A e1=new A();
e1.setb(your_variable);
session.persist(e1);
t.commit();
session.close();
Mention: your naming is quite bad. You should put something else!
Also, with the @ElementCollection annotation you can use java.util.Map collections. In the declaration of your class (in your case, A).
It seems like you should use @ElementCollection and @CollectionTable from JPA: How to annotate Map<Entity,INTEGER> with JPA?