Applying licensing and author to java class - netbeans

I am trying out Visual Paradigm for the first time. I have created a class diagram and used the Update Code button in the diagram navigator to create a java class. The issue I have is, when the class code is created, the license and author information is not being applied to the file. Is there any way to get Netbeans to insert the information when creating the file with the Visual Paradigm interface?
I used the Visual Paradigm plugin for NetBeans to create a class diagram and then used the Update Code tool to generate the Java class. But as I stated above, the licensing and author information are missing.
package onlineshop;
public class Product {
private String name;
private String partNo;
private float price;
public Product(String name, String partNo, float price) {
this.name = name;
this.partNo = partNo;
this.price = price;
}
public String getName() {
return this.name;
}
/**
*
* #param name
*/
public void setName(String name) {
this.name = name;
}
public String getPartNo() {
return this.partNo;
}
/**
*
* #param partNo
*/
public void setPartNo(String partNo) {
this.partNo = partNo;
}
public float getPrice() {
return this.price;
}
/**
*
* #param price
*/
public void setPrice(float price) {
this.price = price;
}
}

Related

The identification variable 'name' is not defined in the FROM clause

I am trying to run a named query in my bean but unfortunately it wont work. I get the following error.
Problem compiling [SELECT d FROM IncentiveEntity d WHERE name = :name].
[38, 42] The identification variable 'name' is not defined in the FROM clause.
Following is my code in the bean.
String s = "SELECT d FROM IncentiveEntity d WHERE d.name= :%s";
s = String.format(s, "bla");
IncentiveEntity a = (IncentiveEntity) em.createQuery(s,IncentiveEntity.class).getSingleResult();
I have tried it many other ways possible like removing colon in the query, but it wont work and give different errors. I have found many solutions online but nothing worked, I had to post it here following is the code for my entity class if it helps.
#Entity
public abstract class IncentiveEntity {
#Id //Primary Key
#GeneratedValue(strategy=GenerationType.AUTO)
private int id;
private String init_name;
#OneToMany(mappedBy="incfk", fetch=FetchType.EAGER)
private List<BeverageEntity> bvgfk;
public List<BeverageEntity> getbvgfk() {
if(this.bvgfk == null)
return new ArrayList<BeverageEntity>();
else
return new ArrayList<BeverageEntity>(this.bvgfk);
}
/**
* #param rooms the rooms to set
*/
public void getbvgfk(List<BeverageEntity> or) {
this.bvgfk = or;
}
public int getid() {
return this.id;
}
public String getName(){
return init_name;
}
public void setName(String name){
this.init_name = name;
}
}

Using JPA 2.1 Converter with Java 1.8 Time API reults in Eclipse JPA-Error "The left and right expressions type must be of the same type"

I'm using Eclipe IDE Neon.2 working on a JavaEE 7 project (JPA 2.1 & Java 8).
In my Entities new Java 8 Time API is used and therefore i need to use JPA-AttributeConverter to convert them to sql-datatypes. In most cases i want to use named queries with JPQL.
#Entity
#NamedQuery(name = Account.QUERY_FIND_LOGGED_USER_TODAY, query = "SELECT a from Account a where a.lastLoggedInDate == CURRENT_DATE")
public class Account implements Serializable {
private static final long serialVersionUID = 1L;
public final static String QUERY_FIND_LOGGED_USER_TODAY = "account_find_logged_user_today";
#Id
private Integer id;
private String name;
#Convert(converter = LocalDateAttributeConverter.class)
private LocalDate lastLoggedInDate;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public LocalDate getLastLoggedInDate() {
return this.lastLoggedInDate;
}
public void setLastLoggedInDate(LocalDate lastLoggedInDate) {
this.lastLoggedInDate = lastLoggedInDate;
}
}
The AttributeConverter looks like this
#Converter(autoApply = true)
public class LocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> {
#Override
public Date convertToDatabaseColumn(LocalDate locDate) {
return (locDate == null ? null : Date.valueOf(locDate));
}
#Override
public LocalDate convertToEntityAttribute(Date sqlDate) {
return (sqlDate == null ? null : sqlDate.toLocalDate());
}
}
Eclipse shows me an error-message pointing to "a.lastLoggedInDate == CURRENT_DATE" saying
The left and right expressions type must be of the same type.
Is this a real JPA-Error, or does Eclipse-JPA-Validation not support the combination JPA-Converter & JPQL.

JPA #Id annoation

i want to insert into a table with a specified value,but it just don't work,
here is my code:
#Id
#Column(insertable=true,updatable=true)
public Long getS_id() {
return s_id;
}
#Resource(name="studentService")
private StudentService stus;
Student student = new Student();
student.setS_id(123213L);
student.setName("vincent");
stus.add(student);
If I change:
#Id
#Column(insertable=true,updatable=true)
public Long getS_id() {
return s_id;
}
to this:
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(insertable=true,updatable=true)
public Long getS_id() {
return s_id;
}
and don't set s_id manualy it works well.
here my student class
#Entity()
#Table(name="stu_info")
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
/**
* 学生的学号
*/
private Long s_id;
/**
* 学生姓名
*/
private String name;
/**
* 学生性别
*/
private String sex;
/**
* 学生生日
*/
private Date birthday;
/**
* 学生电话号码
*/
private String telephone;
/**
* 学生所在年级
*/
private String grade;
/**
* 学生所在班级
*/
private String classes;
/**
* 学生编号
*/
private int number;
/**
* 学生父亲姓名
*/
private String father_name;
/**
* 学生母亲姓名
*/
private String mother_name;
/**
* 学生个人疾病史
*/
private String diseases_history;
#Id
#Column(insertable=true,updatable=true)
public Long getS_id() {
return s_id;
}
public void setS_id(Long s_id) {
this.s_id = s_id;
}
#Column(length=32)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#Column(length=12)
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
#Temporal(TemporalType.DATE)
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
#Column(length=12)
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
#Column(length=32)
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
#Column(length=32)
public String getClasses() {
return classes;
}
public void setClasses(String classes) {
this.classes = classes;
}
#Column(length=32)
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
#Column(length=32)
public String getFather_name() {
return father_name;
}
public void setFather_name(String father_name) {
this.father_name = father_name;
}
#Column(length=32)
public String getMother_name() {
return mother_name;
}
public void setMother_name(String mother_name) {
this.mother_name = mother_name;
}
#Column(length=32)
public String getDiseases_history() {
return diseases_history;
}
public void setDiseases_history(String diseases_history) {
this.diseases_history = diseases_history;
}
}
From the limited information posted I would guess you are using SQL Server and to insert a record into an SQLServer table with an explicit value defined for an Identity column requires you to turn on identity inserts for that table.
https://msdn.microsoft.com/en-gb/library/ms188059.aspx
So if you run the above against your table you should then be able to persist using a specific value.
So not really anything to do with JPA.

Optimistic locking not working with spring data couchbase #version

As mentioned in spring data couchbase reference guide, i am trying to enable optimistic locking feature using #Version annotation. My expectation is couchbase will populate version field when a doucument is mutated. But seems like it is not populating the version field. its always 0. Following is my Pojo, and using crudRepository to save the document. when i update i try to send version as 1 to simulate optimitic locking exception. But i didn't get any exception the update went fine. Since the documentation is not helping much, i could not proceed further. Any help will be greatly appreciated?
#Document
public class Project extends BusinessEntity {
private static final long serialVersionUID = 1665165729053936288L;
#NotNull
#Field
private String name;
#Field
private String description;
#Version
private long version;
public Project() {
}
public Project(String name) {
this.name = name;
}
public Project(String name, String description) {
super();
this.name = name;
this.description = description;
}
/**
* #return the name
*/
public String getName() {
return name;
}
/**
* #param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* #return the description
*/
public String getDescription() {
return description;
}
/**
* #param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* #return the version
*/
public long getVersion() {
return version;
}
/**
* #param version the version to set
*/
public void setVersion(long version) {
this.version = version;
}
}
Its my fault. Couchbase populates version field.But we are requried to send version number while saving.
Another reason this could fail is that you need to have a getter for your #version field.

How to make a request factory non-transportable type transportable?

According to this answer: Is com.vividsolutions.jts.geom.Geometry directly transportable using requestfactory? Geometry is ( a particular case of a type that is ) non- transportable using requestfactory.
So then would this work? :
#Entity
public class Poi {
#GeneratedValue(strategy=GenerationType.IDENTITY)
#Id
private Integer id;
#Type(type="org.hibernate.spatial.GeometryType")
private Geometry geom;
//bi-directional many-to-one association to PoiCateg
#ManyToOne
#JoinColumn(name="id_cat")
private PoiCateg poiCateg;
#Version
private Integer version;
public Poi() {
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public Geometry getGeom() {
return this.geom;
}
public void setGeom(Geometry geom) {
this.geom = geom;
}
public PoiCateg getPoiCateg() {
return this.poiCateg;
}
public void setPoiCateg(PoiCateg poiCateg) {
this.poiCateg = poiCateg;
}
//not your standard getters and setters
public String getGeomClient() {
return //result of method that converts from Geometry object to WKT string representation
}
public void setGeomClient(String geom) {
this.geom = // result of method that converts from String to Geometry
}
}
and then my modified entity proxy for Poi would look like:
#ProxyFor(value=Poi.class)
public interface PoiProxy implements EntityProxy {
public Integer getId() ;
public void setId(Integer id);
public PoiCategEntityProxy getPoiCateg() ;
public void setPoiCateg(PoiCateg poiCateg);
//not your standard getters and setters
public String getGeomClient() ;
public void setGeomClient(String geom) ;
}
since getGeomClient and setGeomClient in the server entity contain a geometry type will it be a problem on the client?
EDIT1: forgot about #Version private Integer version; mistake fixed.
Not only it'll work but that's the (simplest) way to make it work.
Alternatives involve using wrappers/builders. I've also seen people using EntityProxys where the stringified value is used as the identifier, but beware that RequestFactory requires a per-request cache.