Problem with nested annotations when using JPA
Working with JPA and nested annotations. Found the nested annotations do not work very well.
Java example:
@Entity
@Table(name="COUNTRIES")
public class Country implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="COUNTRY_ID")
private String countryId;
@Column(name="COUNTRY_NAME")
private String countryName;
//bi-directional many-to-one association to Region
@ManyToOne
@JoinColumn(name="REGION_ID")
private Region region;
//bi-directional many-to-one association to Location
@OneToMany(mappedBy="country", fetch=FetchType.EAGER)
private Set<Location> locations;
.....java constructor getters and setters follow
}
Scala example:
@Entity
@Table(name="COUNTRIES")
class Country extends Serializable{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="COUNTRY_ID")
var countryId:String =_
@OneToMany(mappedBy="country",fetch=FetchType.EAGER)
var locations:Set[String]=_
}
Eclipse highlights these lines as errors: @GeneratedValue(strategy=GenerationType.AUTO)
@OneToMany(mappedBy="country",fetch=FetchType.EAGER)
The error message is: annotation argument needs to be a constant; found GenerationType{<null>}.AUTO{<null>}
However, the problems tab do not show any errors. However, for other annotation types e.g. TemporalType, Eclipse does report an error in the problem tab.
Note that I was successfully able to define this class in the Eclipse Scala interpreter.
Java example:
@Entity
@Table(name="COUNTRIES")
public class Country implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="COUNTRY_ID")
private String countryId;
@Column(name="COUNTRY_NAME")
private String countryName;
//bi-directional many-to-one association to Region
@ManyToOne
@JoinColumn(name="REGION_ID")
private Region region;
//bi-directional many-to-one association to Location
@OneToMany(mappedBy="country", fetch=FetchType.EAGER)
private Set<Location> locations;
.....java constructor getters and setters follow
}
Scala example:
@Entity
@Table(name="COUNTRIES")
class Country extends Serializable{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="COUNTRY_ID")
var countryId:String =_
@OneToMany(mappedBy="country",fetch=FetchType.EAGER)
var locations:Set[String]=_
}
Eclipse highlights these lines as errors: @GeneratedValue(strategy=GenerationType.AUTO)
@OneToMany(mappedBy="country",fetch=FetchType.EAGER)
The error message is: annotation argument needs to be a constant; found GenerationType{<null>}.AUTO{<null>}
However, the problems tab do not show any errors. However, for other annotation types e.g. TemporalType, Eclipse does report an error in the problem tab.
Note that I was successfully able to define this class in the Eclipse Scala interpreter.
Leave a comment
on 2010-05-25 10:21 *
By
This looks suspiciously similar to the following non-Eclipse-specific bug,
http://lampsvn.epfl.ch/trac/scala/ticket/2764
Could you see if you can reproduce the problem outside of Eclipse using the command line compiler.
http://lampsvn.epfl.ch/trac/scala/ticket/2764
Could you see if you can reproduce the problem outside of Eclipse using the command line compiler.
Thanks for the update ...
I'll assume for now that this is a duplicate of the compiler bug that I linked to, so I'll close this one as invalid. If you can successfully compile the project on the command line (ie. command line scalac doesn't give the same error) then please reopen this ticket.
I'll assume for now that this is a duplicate of the compiler bug that I linked to, so I'll close this one as invalid. If you can successfully compile the project on the command line (ie. command line scalac doesn't give the same error) then please reopen this ticket.
Reopened ticket. I can compile it using scalac. Code below.
Cheers.
import java.io.Serializable
import javax.persistence._
import java.math.BigDecimal
import java.util.{Set,Date}
@Entity
@Table(name="EMPLOYEES")
class Employee extends Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="EMPLOYEE_ID")
var employeeId:Long =_
@Column(name="COMMISSION_PCT")
var commissionPct:BigDecimal =_
@Column(name="FIRST_NAME")
var firstName:String =_
@Temporal(TemporalType.DATE)
@Column(name="HIRE_DATE")
var hireDate:Date =_
@Column(name="LAST_NAME")
var lastName:String=_
@OneToMany(mappedBy="country",fetch=FetchType.EAGER)
var locations: Set[String] =_
}
Cheers.
import java.io.Serializable
import javax.persistence._
import java.math.BigDecimal
import java.util.{Set,Date}
@Entity
@Table(name="EMPLOYEES")
class Employee extends Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="EMPLOYEE_ID")
var employeeId:Long =_
@Column(name="COMMISSION_PCT")
var commissionPct:BigDecimal =_
@Column(name="FIRST_NAME")
var firstName:String =_
@Temporal(TemporalType.DATE)
@Column(name="HIRE_DATE")
var hireDate:Date =_
@Column(name="LAST_NAME")
var lastName:String=_
@OneToMany(mappedBy="country",fetch=FetchType.EAGER)
var locations: Set[String] =_
}
OK, thanks ... I'm still fairly confident that this isn't an Eclipse-specific bug. Nevertheless it's only showing up with Eclipse runs scalac in presentation compiler mode, so I'll investigate.
Updating tickets (#1000069, #1000195, #1000213, #1000223, #1000006, #1000021, #1000038, #1000048, #1000051, #1000052, #1000075, #1000103, #1000109, #1000115, #1000119, #1000156, #1000186, #1000207, #1000238, #1000262, #1000263, #380, #389, #683, #1238, #1331, #1635, #1645, #1715, #1729, #1744, #1783, #1839, #1869, #1885, #1890, #1902, #1918, #1919, #1924, #1925, #1946, #1964, #1991, #2131, #2233, #2342, #2348, #2408, #2459, #2499, #2523, #2572, #2582, #2602, #2614, #2615, #2675, #2710, #2745, #2763, #2816, #2830, #2834, #2878, #2879, #2887, #2888, #2901, #2911, #2912, #2922, #2937, #2938, #2942, #2951, #2955, #2957, #2961, #2964, #2965, #2974, #2975, #2989, #2990, #3002, #3055, #3070, #3087, #3135, #3139, #3173, #3182, #3184, #3200, #3213, #3214, #3221, #3243, #3251)
on 2011-03-24 14:18 *
By Iulian Dragos
Updating tickets (#1000199, #1000200, #1000201, #1000204, #1000205, #1000209, #1000210, #1000211, #1000212, #1000215, #1000217, #1000218, #1000220, #1000222, #1000226, #1000227, #1000228, #1000230, #1000231, #1000232, #1000233, #1000235, #1000236, #1000237, #1000239, #1000240, #1000241, #1000242, #1000243, #1000244, #1000248, #1000249, #1000252, #1000253, #1000254, #1000255, #1000256, #1000258, #1000259, #1000032, #1000059, #1000062, #1000163, #1000197, #1000216, #1000221, #1000224, #1000121, #1000175, #1000219, #1000251, #1000069, #1000195, #1000213, #1000223, #1000006, #1000021, #1000038, #1000048, #1000051, #1000052, #1000075, #1000103, #1000109, #1000115, #1000119, #1000156, #1000186, #1000207, #1000238, #1000262, #1000263, #380, #389, #683, #1238, #1331, #1635, #1645, #1715, #1729, #1744, #1783, #1839, #1869, #1885, #1890, #1902, #1918, #1919, #1924, #1925, #1946, #1964, #1991, #2131, #2233, #2342, #2348, #2408)