java - How to persist a custom map with Hibernate/JPA? -


I try to continue a subclassified hashmap in the database using hibernate and JPA annotations I am doing

  import javax.preistence.CollectionTable; Import javax.preistence.Column; Import javax.preistence.ElementCollection; Import javax.preistence.Entity; Import javax.preistence.FetchType; Import javax.preistence.GeneratedValue; Import javax.preistence.Id; Import javax.preistence.MapKeyColumn; Import javax.preistence.Table; @Entity @Table (name = "module") Public class module {@Id @ generatedValue @Column (name = "id") Private ID ID; @column (name = "name") private string name; @column (name = "description") private string description; @ Column (name = "version") private string version; @ElementCollection (fetch = FetchType.EAGER) @CollectionTable (name = "module_parameter") @MapKeyColumn (name = "key") @column (name = "value") Private parameter parameters = new parameter (); // Gates & amp; Setters}   

This parameter gives me the following exception when trying to store this parameter:

  org.hibernate.AnnotationException: The form of non-archive one Invalid attempt to map to @OneToMany, @ManyToMany, or @CollectionOfElements: Module.params   

When I announce the

  private map & lt; String, string & gt; Parameters = new parameter (); Public Parameter Received Parameters () {Return Parameters; }   

I get the following output:

  Hibernate: Modul0_. Id choose as id1_0_, as Modul0_diskripshn descript2_0_, module0_.name name3_0_ , As the module0_. Module module version 4_0_ as version: hibernate: parameter0_ In the form of module_ID as module_i1_0_0_, parameter0_.value value2_1_0_, select parameter0_key as key3_0_module_mapmeter Parameters0_ where parameter0_ Module_id =?   

If I change it

  

Code> Private map & lt; String, string & gt; Parameters = new Hashmap & lt; & Gt; ();

Everything works fine.

How can I tell the hibernate as a parameter collection?

this is untested Perhaps you can try and see that this work Does: Why Not only a Map & lt; String, string & gt; ?

JPA works by using the normal archive interface: list , set , map . Thus, if parameter is-ace map , you can return it as the Map . Change

:

  get public parameter first () {return parameter}; }   

From:

  Public map & lt; String, string & gt; GetParams () {Return Ultimate; }   

In addition, allows lazy loading, ie, because the Hibernate classes Persistent list , PersistentSet , PersistentMap , etc., you can use the structure to return to a parameter that comes back from hibernation.

Therefore, you originally returned the hibernate archive.

Some of this effect:

  public map & lt; String, string & gt; GetParams () {new parameter back (parameter); // parameter is injected with Hibernate's persistentmap. }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -