Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
    
    
Sorry, but i think problem is not there. i already try it before posted this question. –  Robertas Uldukis May 7 at 11:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.