trying to learn how to use PostgeSQL data base, and JAVA with ENUM's and got some problem with casting.
Here is my sql:
CREATE TYPE enum_created_from AS ENUM ('CHAT', 'WEB');
ALTER TABLE contact ADD COLUMN created_from enum_created_from;
UPDATE contact SET created_from='WEB';
Enum file:
public enum ContactCreatedFrom {
WEB, CHAT;
}
JAVA Entity file:
@Column(name = "CREATED_FROM")
@Enumerated(EnumType.STRING)
private ContactCreatedFrom createdFrom;
off course getters and setters.
@Test file using JUnit
@Test
public void testContactCreatedFrom()
{
try
{
@SuppressWarnings("unchecked")
List<Contact> contacts = (List<Contact>) db.createQuery("from Contact where id between 20 and 25").list();
for (Contact c : contacts)
{
System.out.println("Name: " + c.getName());
System.out.println ("Enum: " + c.getCreatedFrom());
}
} catch (Exception e)
{
System.out.println("Exception: " + e);
}
}
And I still getting Exception:
Exception: java.lang.ClassCastException: org.postgresql.util.PGobject cannot be cast to java.lang.String
Can anybody tell me where I'm wrong please.
Regards