Hibernation and padding to CHAR primary key column in Oracle

I have a little problem using Hibernate with a char (6) column in Oracle. Here is the table structure:

CREATE TABLE ACCEPTANCE
(
   USER_ID char(6) PRIMARY KEY NOT NULL,
   ACCEPT_DATE date
);

For records whose user ID is less than 6 characters, I can select them without populating the user ID when executing queries using SQuirreL. I.E. the following returns a record if there is a record with user ID "abc".

select * from acceptance where user_id = "abc"

Unfortunately, when making a selection through Hibernate (JPA), the following returns null:

em.find(Acceptance.class, "abc");

If I inserted this value, it will return the correct entry:

em.find(Acceptance.class, "abc   ");

, , , . Hibernate , , Hibernate? ( , - )

+3
3

CHAR() : -)

, , user_id String . Hibernate Oracle dialect varchar. Hibernate , ( SQuirreL, , , -).

Oracle , varchar2 ; , .

, HQL- rtrim(), Oracle.

+3

, ?

, , 6 db 6 - . - PK, .

( , ), , . ,

  • 6 .
  • varchar2 .

,

  • /
  • / DAO,
  • / , ( . )
+1

I do not think so. However, you can define UserType to damage one place.

0
source

Source: https://habr.com/ru/post/1725745/


All Articles