by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
ZhangBin
@jang675953
image.png
i think the real bind should be TimestampTypeDescriptor, but is not
Marc Magon
@GedMarc
Use converters
@Convert(using=LocalDateTimestampAttributeConverter .class)
private LocalDate myvar;
@Converter()
public class LocalDateTimestampAttributeConverter implements AttributeConverter<LocalDate, Timestamp>
{
    @Override
    public Timestamp convertToDatabaseColumn(LocalDate attribute)
    {
        return (attribute == null ? null : Timestamp.valueOf(attribute.format(DateTimeFormatter.ISO_DATE_TIME)));
    }

    @Override
    public LocalDate convertToEntityAttribute(Timestamp sqlTimestamp)
    {
        return (sqlTimestamp == null ? null : sqlTimestamp.toLocalDateTime().toLocalDate());
    }
}
add it to your persistence.xml file as a class tag, you can also use autoApply to apply to all entities with the field
ZhangBin
@jang675953
thank you, it have been resolved, converter is used to solve the proplem that the entity field type and the colunm is not same
@GedMarc
why using, is it convert?
image.png
Steve Ebersole
@sebersole
@jang675953 using @Convert as opposed to ...?
As to your original question, it feels like you are using a t-sql based dialect (SQL Server or Sybase) where the timestamp datatype is actually a generated value that is effectively a byte array (VARBINARY)
are you certain you are using pgsql dialect when this happens?
also, feel free to ask questions here. but realize that zulip is the "official" community chat platform as stated in the room topic here, so you'll get replies inconsistently
Steve Ebersole
@sebersole
generally speaking, @Convert is a great way to implement these conversions. they are not as efficient as native (User)Type impls, but its not a major diff
ZhangBin
@jang675953
@sebersole yes, I use postgresql with spring-data-jpa and hibernate ,I try all of the java8-time, only OffsetLocalTime is not supported.
Steve Ebersole
@sebersole
never said anything about java8
but ok
fajkovicsasa
@fajkovicsasa

Hi, I'm stuck on what should be a pretty easy task. Connect 2 classes with ONE-TO_MANY relationship. The only unusual thing is that on one table I don't want to link on the ID, but rather on a separate column (which is guaranteed to be unique).

public class NotificationHistory {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    private Long id;
    private Long gameId;
    @NaturalId
    @Column(name = "notification_id", nullable = false, unique = true)
    private Long notificationId;
public class BetReport {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private Double bettingAmount;
    @Enumerated(EnumType.STRING)
    private BetStatus status;
    private String errorMessage;

    @ManyToOne
    @JoinColumn(name = "user_id", nullable = false)
    private User user;

    @ManyToOne
    @JoinColumn(referencedColumnName = "notification_id", nullable = false)
    private NotificationHistory notificationHistory;

ERROR:
Caused by: org.postgresql.util.PSQLException: ERROR: column betreports2_.notification_history_notification_id does not exist

I'm stuck on this for a few hours now. I have no idea why it's trying to find a column notification_history_notification_id (name is a combination of class and property)
Steve Ebersole
@sebersole
you probably want to name the join-column, but your @JoinColumn is missing #name
#referencedColumnName names the column on the "other side" (here notification_id on the NotificationHistory table)
but you'd still want to give the name of the column on the BetReport table
fajkovicsasa
@fajkovicsasa
I added #name and seems to be working
Thansk :)
Steve Ebersole
@sebersole
awesome
monsio
@kaizokun
Hi guys can anyone help me with hibernate criteria API, I have a query thant I want to use to get a limited resulset and also to make a select count to know the real size of the set
4javier
@4javier
Hi.
I just noticed that Hibernate maps boolean value to MySql BIT type. Is it really the best approach? What are the benefits compared to BOOLEAN/TINYINT?
odatadev2021
@odatadev2021
I know this is a hibernate forum. However many java developers might be able to assist me. I want to obfuscate my java jar. I downloaded and run the ProGuard UI.
I open ProGuard UI and Added input jar and on the final stage i clicked Process! button. Process is completely successfully.
Where i see the converted, obfuscated jar file? location of the obfuscated jar file?
2nd question, can i obfuscate the application jar files alone instead of obfuscating rt.jar java file as well?
I have one jar and need to obfuscate it and struggling with the steps.
Does anyone can help me with a easy tool which would obfuscate the jar ?
Rithuik
@rithuiketz
hello
I am facing an issue with hibernate 4 and db2
please see the stack trace here
2020-04-13 00:03:47,810 INFO [stdout] (default task-2) Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: [jcc][10145][10844][3.69.66] Invalid parameter 18: Parameter index is out of range. ERRORCODE=-4461, SQLSTATE=42815
Kanstantsin I.
@Ozymandy
I faced a strange issue which breaks all my understanding of Lazy Loading. I switched a field of an Entity to fetch type lazy and tried to access it outside of transactional. And it is not throwing LazyInitilizationException on my local env, but sometimes(not all time) is throwing on dev environment(aws). Why does it happen?
Kanstantsin I.
@Ozymandy
I found that it works on my local env due to open entitymanager in view, but why this entitymanager sometimes cannot handle lazy loading?
Chris Cranford
@Naros
@Ozymandy A lot of that depends entirely on your data access pattern.
@Ozymandy For example, you might fetch the entity, render the page, and cache the entity in the webapp session-scoped storage. Upon a user UI interaction, a request is sent to the server that pulls the entity from the session-scoped storage and accessing the lazy association. Its at this point you'd get a LazilyInitializationException because the EntityManager gets closed once the page is first rendered. Subsequent calls that access entity state outside the scope of the transaction will otherwise fail.
Kanstantsin I.
@Ozymandy
@Naros I guess your case can happen if I am passing entity object into ModelAndView, but my code is implementing rest service, and resulted object is converting into json after mapping from entity object to DTO. I found why I cannot reproduce LazyInitializationException on my local env - it's due to open in view entity manager. But then I am revealing a new question from my side - why LazyInitializationException sometimes may be thrown despite I have open in view entity manager on dev env(aws)?
Chris Cranford
@Naros
@Ozymandy Sounds like the session for which the entity is associated has been closed; that's the only reason.
I'd look at your transaction/session management
Kanstantsin I.
@Ozymandy
@Naros Yes, it seems like that, but why in most cases it works? Looks like a concurrent behaviour in open in view entity manager. What to show you regarding my transaction management? Configurations?
akhan5
@akhan5
Hi All,
akhan5
@akhan5

I need help regarding entityManager.flush() in between transaction.

I have a springboot application with hikaricp as connection pool.

I have initialized entitymanagerfactory with datasource but whenever I call entityManager.flush() explicitly in dao method. EntityManager takes a connection from connection pool but It does not release a connection and transaction goes into idle state.

if I donot do flush explicitly it works fine that is commit the data after transacation.
but I want to do synchronization with database within transaction using entityManager.flush() method explicitly.

I have tried to add jpa properties to solve the issue but could not reach a solution.

can anyone help me ?

prog20901
@prog20901

Hi,

How to calculate percentage in java?

Some uses big decimal and other uses different ways..

I want to calculate percentage and limit to 2 decimal and save it in a string

please let me know

thanks

prog20901
@prog20901

Suggestion of 10 (TEN) crucial items for developing web application 2020

Could someone suggest the best tool/framework for small or medium size or enterprise web application for 2020 - 10 to 1000 users and millions of records

#1 - Best Unit test case framework

#2 - Best NoSQL Database

#3 - Best Relation Database

#4 - Best Synchronous Framework

#5 - Best Asychronous Framework

#6 - Best Front-End Framework (Active Development, Max Support)

#7 - Best Debugging Tool

#8 - Best Performance Tuning Tool

#9 - Best Code Coverage Tool

#10 - Best DB migration tool (ex: flyway)

Thanks.

Steve Ebersole
@sebersole
@Ozymandy There is a setting to allow Hibernate to open a new Session to initialize a proxy if the Session that loaded it has been closed. See hibernate.enable_lazy_load_no_trans
the default in Hibernate itself is false. I think WildFly might set that to true though and conceivably other envs do as well
prog20901
@prog20901
Is the following is the right way to go ???
Delete with group by multiple columns exclude and donot exclude - MySQL

Let's assume i have employee table which has the following 4 columns

id (primary key) - auto generated
name
father_name
mother_name

Assume many duplicate records exist with same name, father name and mother name

Case1: I want to remove all the records except the first inserted record group by name, father name, mother name
Case2: I want to remove all the records except the last inserted record group by name, father name, mother name
Case3: I want to remove all the duplicate records

I'm using mysql. Please advise how to write a delete query for the above 3 cases

Is the following is correct ???

Case1: Keep Latest i.e Highest Id

delete t1 FROM employee t1
INNER JOIN dates t2
WHERE
t1.id < t2.id AND
t1.name= t2.name AND
t1.father_name = t2.father_name AND
t1.mother_name = t2.mother_name

Case2: Keep Oldest i.e Lowest id

delete t1 FROM employee t1
INNER JOIN dates t2
WHERE
t1.id > t2.id AND
t1.name= t2.name AND
t1.father_name = t2.father_name AND
t1.mother_name = t2.mother_name

Case3:

delete t1 FROM employee t1
INNER JOIN dates t2
WHERE
t1.name= t2.name AND
t1.father_name = t2.father_name AND
t1.mother_name = t2.mother_name

Kanstantsin I.
@Ozymandy

the default in Hibernate itself is false. I think WildFly might set that to true though and conceivably other envs do as well

@sebersole I am not using any application servers. Just tomcat. And I am running project on aws with docker image which just run application file

Steven Gentens
@sgentens
Hey there, I don't know whether this is the right channel for hibernate ehcache related questions (but I didn't see a more specific one yet):
In our project we're using Spring Framework 5 / Spring Boot 2 with hibernate 5.3.14.Final and ehcache 2.10.6. Now I've noticed that the EhCacheRegionFactory has been removed from hibernate-ehcache 5.2 to 5.3. Which region factory class are we supposed to specify now to activate the L2 cache?