I'm looking at some legacy code that is an Entity that is mapped with JPA. This object also gets converted to XML via JaxB. I'm new to JPA and JaxB. Below is a code sniplet:
@Entity
@Audited
@Table(name = "TTRANSACTION_ITEM")
@DiscriminatorColumn()
public class TransactionItem {
@Transient
private Order order;
private List<Comment> comments;
private List<Attachment> attachments;
@XmlTransient
private Timestamp lastPrintDate;
private String createdBy;
@XmlTransient
private Timestamp creationDate;
@XmlTransient
private Timestamp lastUpdateDate;
private String lastUpdateBy;
private int isSendDiploma;
@Transient
private Student aStudent;
// NOTE, I'm forced to make THESE TWO PUBLIC or else i won't show in XML:
@Transient
public String studentFirstName;
@Transient
public String studentLastName;
...
...
}
Question:
1) Does the name of the elements in the generated xml file come from the fields of the database table? For example, in the generated xml file, I see sendDiploma instead of isSendDiploma.
2) Why does instance variable need to be private? I changed it to public or protected and the element will not appear in the XML. Oddly, if I want to include extra variables such as (studentFirstName) in the java code to xml, I need to use a public . For example public String studentFirstName. Because I don't want studentFirstName to be in the database, I use @Transient. I added studentFirstName because for whatever reason, I don't see any elements containing "aStudent" and it's values such as firstName and lastName.
3) How come the element order in the XML is unpredictable? Where does the order come from? I don't see any JaxB annotation that is used to dictate the ordering. Unfortunately, I can't include the xml output here because it's sensitive