• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

You will need to rewrite or cast the expression.is of type dot_status but expression is of type char

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there guys!

I am a new comer at Java. I am trying to learn some basic of SPRING. So nowdays I am stucked with ENUM.
I created ENUM type in POSTGRESQL, created the same ENUM in Java. These both are mapped to each other. But when I run the app it is said:

2023-11-26T06:51:50.148-05:00  WARN 20348 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 42804
2023-11-26T06:51:50.148-05:00 ERROR 20348 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: column "dot_status" is of type dot_status but expression is of type character varying
You will need to rewrite or cast the expression.

I did everything I could. I realize that this erros is related somehow to casting types. But I really stucked. Please, could anybody help me?

Thank you!
 
Marshal
Posts: 79063
376
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please show us how you are selecting your value form the database. How are you casting it?

If you are really a beginner at Java®, maybe is would be better to learn Java® basics before you try adding Spring to your programming.
 
Marshal
Posts: 28140
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please show us how you are selecting your value form the database. How are you casting it?



It maybe looks to me like that error occurs when writing to the database. But anyway, trying to debug Java code without actually seeing the code is pointless. We would need to see the code.
 
Paul Clapham
Marshal
Posts: 28140
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After a bit of web searching I found an article which claims to describe the full process described: The Generic Way To Convert Between Java and PostgreSQL Enums. It sure looks like a cast might help, although that of course is just speculation.
 
Andrew Pi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

Please show us how you are selecting your value form the database. How are you casting it?

If you are really a beginner at Java®, maybe is would be better to learn Java® basics before you try adding Spring to your programming.



Thank you!

@Enumerated(EnumType.STRING)
@Column(name="dot_status")
private Dot_status dot_status;
 
Andrew Pi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:After a bit of web searching I found an article which claims to describe the full process described: The Generic Way To Convert Between Java and PostgreSQL Enums. It sure looks like a cast might help, although that of course is just speculation.



@Transactional
public void addNewDotRecord(Dot_value dotValue) {

dotValue.setDot_date(new Date());
// dotValue.setDot_status(Dot_status.PASSED);
dotValue.set_id(11);
// dotValue.setNumber("22");

dotRepository.save(dotValue);
}

Something like that. Please, do not pay attention for comments, I tried everypossible way I could even though with "hard coding".
 
Andrew Pi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:After a bit of web searching I found an article which claims to describe the full process described: The Generic Way To Convert Between Java and PostgreSQL Enums. It sure looks like a cast might help, although that of course is just speculation.



OMG!
It helped me. Thank you very much!

CREATE CAST (varchar AS order_status) WITH INOUT AS IMPLICIT;
 
reply
    Bookmark Topic Watch Topic
  • New Topic