JPA - variables double are being rounded - spring

I have a model entity like this:
#Entity
public class Produtos{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String nome;
private Long quantidade;
private boolean frete;
private Double precoNovo;
private Double precoAntigo;
private boolean promocao;
private boolean variacaoCor;
private String[] cores;
private String corUnica;
}
when i use (private Double precoAntigo) to save the product price, the spring rounds the value, ex: 2500.50 to 2500, how do I disable this option?

https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Column.html#precision()
https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Column.html#scale()
#Column(scale=2)
private Double precoNovo;
#Column(scale=2)
private Double precoAntigo;

Related

Hibernate Enver - Listening for only one change in referenced class

I have an entity as shown below that I am auditing using Hibernate Enver
#Entity
#Table(name = "watch_item")
#Audited
public class WatchItemEntity implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Type(type = "uuid-char")
#Column(name = "watch_item_id", columnDefinition = "VARCHAR(36)")
private UUID watchItemId;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "watch_model_id")
private WatchModelEntity watchModel;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "private_user_id")
private PrivateUserEntity privateUser;
private String serialNumber;
private Integer productionYear;
private String generalCondition;
private Boolean isMovementFullyFunctional;
private Boolean isInOriginalCondition;
private String comment;
private Boolean isProofOfPurchaseAvailable;
private String country;
private Boolean isCustomsDeclared;
private Boolean hasPaper;
private Boolean hasBox;
private String otherAccessories;
#CreatedDate private LocalDateTime createdDate;
#LastModifiedDate private LocalDateTime modifiedDate;
private String lastServiceProvider;
private LocalDate lastServiceDate;
private BigDecimal lastServiceCost;
private BigDecimal purchasedPrice;
private LocalDate purchasedOn;
...
}
As you can see, it has a PrivateUserEntity field. I want Hibernate Envers to record a change when the privateUser changes (and not record changes in PrivateUserEntity that correspond to the privateUser). However, I don't want to create a Private_User_Aud table. To give some context, a WatchItem can only be owned by one PrivateUser and hence, when the PrivateUser field changes, that means that the WatchItem's owner changed. The entity can be seen below
#Entity
#Table(name = "private_user")
public class PrivateUserEntity implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Type(type = "uuid-char")
#Column(name = "private_user_id", columnDefinition = "VARCHAR(36)")
private UUID privateUserId;
#OneToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "user_id")
private UserEntity user;
#LastModifiedDate private LocalDate modifiedDate;
private String title;
private String firstName;
private String lastName;
private String phone;
private LocalDate dateOfBirth;
private String email;
private String gender;
private String nationality;
private String residencyPermitType;
private LocalDate residencyPermitValidSince;
private String preferredLanguage;
...
}
Is this possible? And if so, how?
You can disable audit for it, doesn't work?
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "private_user_id")
#NotAudited
private PrivateUserEntity privateUser;

I am working with Spring boot, Spring-data, ThymeLeaf. i am movie ticket is booking it is Should be able to tell the empty/Booked seats of a cinema

this is my column values. I am booking per day 20 tickets after 20 tickets booked it should able to tell ticket is full. How can I achieve this?
#Entity
#Table(name="bookings")
public class BookEntity {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String firstname;
private String lastname;
private String theatrename;
private String moviename;
private String bookdate;
private String showtime;
private int price;
private int tickets;
private int totalprice;

Spring JPA Update Entity

I'm trying to update my user entity and I have an error that comes to mind:
ERROR: A NULL value violates the NOT NULL constraint of the "id" column Detail: The failed row contains (null, 1, 1)
The problem surely stems from my relationship between user and profile which is n-n
public class Utilisateur implements Serializable {
private static final long serialVersionUID = 1L;
#Id
private Integer id;
private Integer fixe;
private Boolean deleted;
private Boolean actif;
private String email;
private Integer mobile;
private String motDePasse;
private String nom;
private String prenom;
#ManyToMany
private List<Profil> profils = new ArrayList<Profil>();
public Utilisateur() {
}
}
public class Profil implements Serializable {
private static final long serialVersionUID = 1L;
#Id
private Integer id;
private String codeProfil;
private String libelleProfil;
#JsonManagedReference
#ManyToMany
private List<MenuAction> menuActions = new ArrayList<MenuAction>();
public Profil() {
}
}
How you generate value for your id?
Seems you need some way to generate value for you ID.
For example, use #GeneratedValue, like:
#GeneratedValue(strategy = IDENTITY)

Spring Data JPA Mapping Exception No Dialect mapping for JDBC type: -9

I am trying to use a projection and am getting the following error. Not sure what the issue is.
Here is the projection:
public interface UserMini {
Long getApproverKey();
String getEmailAddress();
String getFirstName();
String getLastName();
Long getUserKey();
String getUserName();
}
Here is the Query in the repository:
#RestResource(path="getUserMini")
#Query(value="SELECT approverKey, emailAddress, firstName, lastName, userKey, userName FROM [dbo].BdmUser WHERE userKey = :userKey ", nativeQuery=true)
UserMini getUserMini(#Param("userKey") long userKey);
Here is the Entity
#Table (name="[BdmUser]")
#Entity
public class BdmUser {
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
private Long userKey;
private Long priceListKey;
private String firstName;
private String lastName;
private String userName;
private String emailAddress;
private String password;
private Boolean active;
private Long approverKey;
private BigDecimal orderLimit;
private Long salesOfficeKey;
private Long reportsToId;
private Boolean requiresOrderApproval;
private Date lastLoginDate;
private String rowIsCurrent;
private Date rowStartDate;
private Date rowEndDate;
#Column(name="HashByteValueType1", updatable=false, insertable=false)
private String hashByteValueType1;
#Column(name="HashByteValueType2", updatable=false, insertable=false)
private String hashByteValueType2;
private String rowChangeReason;
#Column(name="DQScoreKey")
private Integer dqScoreKey;
private Integer insertAuditKey;
private Integer updateAuditKey;
Try to cast the NVARCHAR to VARCHAR in your query
CONVERT(varchar,theNVarcharColumn)

I want to create an entity X

I want to create an entity X with atributes.
Everything is right except the attribute "permissions" :
public class X implements Serializable{
#Id
#GeneratedValue(strategy=GenerationType.IDENTITY)
private Long idNotateur;
#NotEmpty
private String nomNotateur;
#NotEmpty
private String prenomNotateur;
#NotEmpty
private String fonctionNotateur;
#NotEmpty
private String userNotateur;
#NotEmpty
private String passNotateur;
#ManyToOne
#JoinColumn(name="id_poste")
private Poste poste;
#ManyToOne
#JoinColumn(name="id_dir")
private Direction direction;
#OneToMany(mappedBy="notateur")
private Collection<Employe> Employes;
private Collection<Long> permissions;
getters & setters ...
public Collection<Long> getPermissions() {
return permissions;
}
public void setPermissions(Collection<Long> permissions) {
this.permissions = permissions;
}
}
Then I came across the following error: Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Collection, at table: X, for columns: [org.hibernate.mapping.Column(permissions)]
So how to solve it?
I'm using Spring MVC Hibenate

Resources