1

I use Hibernate version 3.6. I have to store Class instance in database (e.g. Integer.class) and probably i can do it - NetBeans dont show error as in case of Object.

My Groups table:

@Entity
public class Groups implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    private Class classOfGroup;

    public void setClassOfGroup(Class classOfGroup) {
        this.classOfGroup = classOfGroup;
    }

    public Class getClassOfGroup() {
        return classOfGroup;
    }

    private void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }
}

And AdditionalInformationGroup table:

@Entity
public class AdditionalInformationGroup implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    private Class groupClass;
    private Boolean uniqueValue;

    public void setUniqueValue(Boolean uniqueValue) {
        this.uniqueValue = uniqueValue;
    }

    public Boolean getUniqueValue() {
        return uniqueValue;
    }

    public void setGroupClass(Class groupClass) {
        this.groupClass = groupClass;
    }

    public Class getGroupClass() {
        return groupClass;
    }

    private void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }
}

When I do this:

List<AdditionalInformationGroup> additionalInformationGroups = 
s.createCriteria(AdditionalInformationGroup.class)
.add(Restrictions.eq("groupClass", group.getClassOfGroup())).list();

i got Exception:

Exception in thread "AWT-EventQueue-0" org.hibernate.QueryException: Unsupported discriminator type null
    at org.hibernate.loader.criteria.CriteriaQueryTranslator.getTypedValue(CriteriaQueryTranslator.java:499)
    at org.hibernate.criterion.SimpleExpression.getTypedValues(SimpleExpression.java:71)
    at org.hibernate.loader.criteria.CriteriaQueryTranslator.getQueryParameters(CriteriaQueryTranslator.java:251)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
    at Views.ConditionDialog.setFieldList(ConditionDialog.java:85)

I checked that, there is no null at my instance of Groups class. Have i got a bug here, or i can't store instance of Class via hibernate?

2
  • 1
    I'm not sure the exception is caused by your use of fields of type Class. But why don't you simply store the class name, as a String? Commented Dec 3, 2011 at 23:47
  • that complicate my code a bit and i want to check all possible solutions. Commented Dec 4, 2011 at 0:01

1 Answer 1

1

If the provided class mapped in hibernate you will face such issue. But if the class is not mapped inside hibernate you will be able to store it successfully.

JIRA already raised here. There are some workaround for the same as well , you can find workaround in JIRA

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.