-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: NULL-Werte in einem Composite-Identifier
PostPosted: Wed Oct 05, 2011 6:31 am 
Newbie

Joined: Wed Oct 05, 2011 4:02 am
Posts: 1
Hallo zusammen,

ich habe eine Konstellation, in der ein fachlicher Schlüssel durchaus Felder enthalten kann, die nullable sind. Da die Datenbank das nicht unterstützt, muss die (fachliche) null immer in einen Dummy-Null-Wert (z.B. "<null>") konvertiert werden. Das würde ich gerne über einen UserType realisieren - leider führt das dazu, dass die Entität von Hibernate dann nicht mehr geladen werden kann. Welche Möglichkeiten habe ich, dieses Problem in den Griff zu bekommen?

Primary Key:
Code:
@Embeddable
public class MyPrimaryKey implements Serializable, Cloneable {

    // some attributes

    // Kann fachlich "null" - soll in der DB als "<null>" repräsentiert werden
    @Column(name = "BANKCODE", nullable = true, length = 30)
    @Type(type = "nullMap<null>")
    @Size(max = 30)
    private java.lang.String bankCode;

    @Column(name = "ACCOUNTID", nullable = false, length = 40)
    @Type(type = "trimmedString")
    @NotNull
    @Size(min = 1, max = 40)
    private java.lang.String accountId;

    // other code
}


User Type:
Code:
    @Override
    public final Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws SQLException {
        final String value = rs.getString(names[0]);
        if (value == null || rs.wasNull() || "<null>".equals(value)) {
            return null;
        } else {
            value = value.trim();
        }
    }


    @Override
    public final void nullSafeSet(PreparedStatement st, Object value, int index) throws SQLException {
        if (value == null) {
            st.setString(index, "<null>");
        } else {
            final String strValue = ((String) value).trim();
            st.setString(index, strValue);
        }
    }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.