[
https://jira.jboss.org/jira/browse/JBIDE-2077?page=com.atlassian.jira.plu...
]
Vitali Yemialyanchyk commented on JBIDE-2077:
---------------------------------------------
Here is my view to implement it:
1) Add context menu to "Package Explorer"/"Navigator"/"Java
editor" for java class "Make it mapped via JPA";
2) For class Address (for example) add:
@Entity <-- add this
// name defaults to the unqualified classname
public class Address
implements java.io.Serializable { <-- add this
// Entity must have a no-argument public or protected constructor <-- add this if
no constructor
public Address() {} <-- add this if no constructor
}
3) for getters:
...
@Column(name="addressID") <-- add this
public String getAddressID() {} <-- add this - for property-based access
for private/protected field - property-based access using getters/setters;
for public fieilds - field-based access;
@Column(name="addressID") <-- add this - for field-based access
public String addressID;
4) for transient properties - add @Transient annotation for getters/setters;
5) for all abstract classes in the bundle add this comment
// abstract class can't be an entity <-- add this
6) for all abstract methods in the bundle add this comment
// abstract method not suitable for the entity <-- add this
7) try to intellectually define primary id - for example only 1 property in class with
name id or property which contains class name and id, "?some other methods?"
@Id
// primary key <-- add this
public String getAddressID() {
}
8) try to define composite keys - is it posiible?
9) try to define @OneToMany and @ManyToMany relationships;
10) try to define @Inheritance and it's strategy SINGLE_TABLE - for example;
11) things which is possible to ask the user:
a) DB connection for this java classes bundle - if user point it - we could generate
better persistent model;
b) in common case it is possible to ask the user about any ambiguity in the bundle and
possible use checkbox "use deaults"
"Make this class and its related classes mapped via JPA"
--------------------------------------------------------
Key: JBIDE-2077
URL:
https://jira.jboss.org/jira/browse/JBIDE-2077
Project: Tools (JBoss Tools)
Issue Type: Feature Request
Components: Hibernate
Reporter: Vitali Yemialyanchyk
Assignee: Vitali Yemialyanchyk
Priority: Minor
Fix For: 3.0.0.beta1
Denis Golovin:
>>>
Let's imagine I have several (say 10) classes that I'd like to make
persistent. The classes form completed domain model.
I decided to use hibernate and JPA annotations, I have lets say JBDS
1.1.0 or JBossTools 2.1.0 installed.
Question is what I should do to make my model persistent? It there
anything that helps me to do it?
Now I see only way. I have to go through all classes and add annotations
for class and for fields.
>>>
Max Andersen:
>>>
Having a "Make this class and its related classes mapped via JPA" would be
an interesting Refactoring to implement.
Should basically just work like this:
makePersistent(ITypeRoot clazz, Set processed) {
add @Entity
Find most likely id property and add @Id
processed.add(selectedClass);
associations = getAssociatedClasses(selectedClass);
foreach class in associations {
if(!processed.contains(class)) {
makePersistent(class, processed);
}
}
}
There then might be some exceptional cases like handling version properties, temporal
values and
non-JPA supported mappings which Hibernate would be able to understand/map.
>>>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira