简体   繁体   中英

Translate hibernate mapping anotations to hbm.xml file

I have such hibernate mapping annotation and I need to translate it to xml one.

@Entity
@Table(name = "nodes")
public class DefaultDiagramNode {

   .....

   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
   @JoinColumn(name = "node_id", referencedColumnName = "id")
   private Set<NodeProperty> properties;
}

Here is my sql table structure:

CREATE TABLE nodes (
  id           VARCHAR(255) NOT NULL,
  logical_id   VARCHAR(255) NOT NULL,
  graphical_id VARCHAR(50)  NOT NULL,
  type         VARCHAR(50)  NOT NULL,
  diagram_id   BIGINT,
  PRIMARY KEY (id),
  FOREIGN KEY (diagram_id) REFERENCES diagrams (diagram_id)
);    


CREATE TABLE node_properties (
  property_id VARCHAR(255) NOT NULL,
  name        VARCHAR(50)  NOT NULL,
  value       VARCHAR(255) NOT NULL,
  type        VARCHAR(50)  NOT NULL,
  node_id     VARCHAR(255),
  PRIMARY KEY (property_id),
  FOREIGN KEY (node_id) REFERENCES nodes (id)
);

How can I do it?

Annotations really are a better choice for a new application. They are easier to read, remove the obtuse relationship between POJO and XML, and they less will result in less lines of code to maintain later. The annotations will also make it far easier to refactor your applications using IDEs such as Eclipse or IntelliJ.

Is there a pressing need to go back to XML? Otherwise, I'd avoid it.


Edit:

Ah, makes sense since you're using Thrift. Have have you tried looking at Swift? You may be able to just add these annotations to your Hibernate entity classes. https://github.com/facebook/swift/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM