RE: HibernateEntityValueEncoder NullPointerException - Composite/Compund Primary Key Issue
Kalle, i really greatly appreciate the help that Lance Java provided to me (incredibly helpful, explained things, linked to documents, provided code examples and snippets, really one of the best bitys of help I've ever gotten from the StackOverflow community), but at this point, i'm going to push for adding an id column to the database table and testing that change against existing functionality. this ValueEncoder approach is becoming untenable, as i have to keep an eye to the future for maintenance, etc. i'm absolutely not trying to create a crud project where sql must be manually written, and i need to have others on my team be able to maintain and extend the initial functionality i'm building out right now. while this may eventually work with enough tinkering, it's become evident to me that what should be a very simple project is becoming complex, and I would really like to avoid that. Again, thanks to LanceJava for his incredible help. – aaron witt – -Original Message- From: Kalle Korhonen [mailto:kalle.o.korho...@gmail.com] Sent: Wednesday, January 21, 2015 7:15 PM To: Tapestry users Subject: Re: HibernateEntityValueEncoder NullPointerException - Composite/Compund Primary Key Issue I see Lance already answered to your question on Stackoverflow. Follow his advice and make sure you contribute the encoder. After that, you may hit another issues with tynamo not recognizing @IdClass (see an old issue https://jira.codehaus.org/browse/TYNAMO-168), whether it matters to you, I'm not sure. I've used IdClasses before but not extensively, and don't recall whether I've had them on tynamo-model or if I've simply ignored them from it. As both Thiago and Lance mentioned, it's best to avoid composite keys with Hibernate but I'm pretty sure you can get it to work if you need to. I'm always happy to apply patches and please open an issue on github ( https://github.com/tynamo/tapestry-model) if you hit a specific issue with tynamo-model (you may but you are not there yet :P ). Kalle On Tue, Jan 20, 2015 at 11:43 AM, Witt, Aaron wrote: > Hi Tapestry Users, > > I'm using a CRUD framework called Tynamo, which in turn relies on > Apache Tapestry and Hibernate. This all works fine, except for when I > try to use it for CRUD on a table with a composite/compound primary key. > I've decided not to go the @EmbeddedId route, since it seems to not > work at all with the framework. That being said, I have been using the > @IdClass method, which is mostly working; I think I'm a line or two of > code away from success. > The issue is that when it starts using reflection to build the > objects, it blows up and says, > org.apache.tapestry5.ioc.internal.util.TapestryException, caused by > java.lang.NullPointerException at > org.apache.tapestry5.internal.hibernate.HibernateEntityValueEncoder.(HibernateEntityValueEncoder.java:51). > I honestly have no idea what's the deal here, but since I have normal > table CRUD operation working for numerous other tables, I would assume > this is somehow related to this table using a composite/compound primary key. > One thing I did try was to move the static inner class to its own > package and remove the staticclass modifier, but the exact same error > occurred. > You can see my class below: > > package com.company.crud.entities; > > > > import java.io.Serializable; > > > > import javax.persistence.Column; > > import javax.persistence.Entity; > > import javax.persistence.Id; > > import javax.persistence.IdClass; > > > > import > com.company.crud.entities.TransferExtension.TransferExtensionPK; > > > > @Entity(name = "Transfer_Extensions") > > @IdClass(TransferExtensionPK.class) > > public class TransferExtension implements Serializable { > > private static final long serialVersionUID = 1L; > > > > @Id > > // @NotNull(message = "Please supply a Script Code") > > // @Length(min = 3, max = 4) > > @Column(name = "Division", nullable = false) > > private String scriptCode; > > > > @Id > > // @NotNull(message = "Please supply a Transfer Type") > > // @Length(min = 3, max = 6) > > @Column(name = "Transfer_Type", nullable = false) > > private String transferType; > > > > @Column(name = "Extension", nullable = true) > > private String englishExtension; > > > > @Column(name = "Span_Extension", nullable = true) > > private String spanishExtension; > > > > @Column(name = "Call_Type", nullable = true) > > private String callType; > > >
RE: HibernateEntityValueEncoder NullPointerException - Composite/Compund Primary Key Issue
Thanks, Kalle! I'm still trying to work through it, so you're right, if I need/request a patch, I'm not quite there yet. I'll be in touch as I figure this out, I appreciate the help! – aaron witt – -Original Message- From: Kalle Korhonen [mailto:kalle.o.korho...@gmail.com] Sent: Wednesday, January 21, 2015 7:15 PM To: Tapestry users Subject: Re: HibernateEntityValueEncoder NullPointerException - Composite/Compund Primary Key Issue I see Lance already answered to your question on Stackoverflow. Follow his advice and make sure you contribute the encoder. After that, you may hit another issues with tynamo not recognizing @IdClass (see an old issue https://jira.codehaus.org/browse/TYNAMO-168), whether it matters to you, I'm not sure. I've used IdClasses before but not extensively, and don't recall whether I've had them on tynamo-model or if I've simply ignored them from it. As both Thiago and Lance mentioned, it's best to avoid composite keys with Hibernate but I'm pretty sure you can get it to work if you need to. I'm always happy to apply patches and please open an issue on github ( https://github.com/tynamo/tapestry-model) if you hit a specific issue with tynamo-model (you may but you are not there yet :P ). Kalle On Tue, Jan 20, 2015 at 11:43 AM, Witt, Aaron wrote: > Hi Tapestry Users, > > I'm using a CRUD framework called Tynamo, which in turn relies on > Apache Tapestry and Hibernate. This all works fine, except for when I > try to use it for CRUD on a table with a composite/compound primary key. > I've decided not to go the @EmbeddedId route, since it seems to not > work at all with the framework. That being said, I have been using the > @IdClass method, which is mostly working; I think I'm a line or two of > code away from success. > The issue is that when it starts using reflection to build the > objects, it blows up and says, > org.apache.tapestry5.ioc.internal.util.TapestryException, caused by > java.lang.NullPointerException at > org.apache.tapestry5.internal.hibernate.HibernateEntityValueEncoder.(HibernateEntityValueEncoder.java:51). > I honestly have no idea what's the deal here, but since I have normal > table CRUD operation working for numerous other tables, I would assume > this is somehow related to this table using a composite/compound primary key. > One thing I did try was to move the static inner class to its own > package and remove the staticclass modifier, but the exact same error > occurred. > You can see my class below: > > package com.company.crud.entities; > > > > import java.io.Serializable; > > > > import javax.persistence.Column; > > import javax.persistence.Entity; > > import javax.persistence.Id; > > import javax.persistence.IdClass; > > > > import > com.company.crud.entities.TransferExtension.TransferExtensionPK; > > > > @Entity(name = "Transfer_Extensions") > > @IdClass(TransferExtensionPK.class) > > public class TransferExtension implements Serializable { > > private static final long serialVersionUID = 1L; > > > > @Id > > // @NotNull(message = "Please supply a Script Code") > > // @Length(min = 3, max = 4) > > @Column(name = "Division", nullable = false) > > private String scriptCode; > > > > @Id > > // @NotNull(message = "Please supply a Transfer Type") > > // @Length(min = 3, max = 6) > > @Column(name = "Transfer_Type", nullable = false) > > private String transferType; > > > > @Column(name = "Extension", nullable = true) > > private String englishExtension; > > > > @Column(name = "Span_Extension", nullable = true) > > private String spanishExtension; > > > > @Column(name = "Call_Type", nullable = true) > > private String callType; > > > > @Column(name = "Call_Center", nullable = true) > > private String callCenter; > > > > public TransferExtension() { > > } > > > > public TransferExtension(String scriptCode, String transferType, > > String englishExtension, String spanishExtension, String > callType, > > String callCenter) { > > > > this.callCenter = callCenter; > > this.callType = callType; > > this.englishExtension = englishExtension; > > this.scriptCode = scriptCode; > > this.spanishExtension = spanishExtension; > > this.transferType = transferType; > > } > > > >
Re: HibernateEntityValueEncoder NullPointerException - Composite/Compund Primary Key Issue
I see Lance already answered to your question on Stackoverflow. Follow his advice and make sure you contribute the encoder. After that, you may hit another issues with tynamo not recognizing @IdClass (see an old issue https://jira.codehaus.org/browse/TYNAMO-168), whether it matters to you, I'm not sure. I've used IdClasses before but not extensively, and don't recall whether I've had them on tynamo-model or if I've simply ignored them from it. As both Thiago and Lance mentioned, it's best to avoid composite keys with Hibernate but I'm pretty sure you can get it to work if you need to. I'm always happy to apply patches and please open an issue on github ( https://github.com/tynamo/tapestry-model) if you hit a specific issue with tynamo-model (you may but you are not there yet :P ). Kalle On Tue, Jan 20, 2015 at 11:43 AM, Witt, Aaron wrote: > Hi Tapestry Users, > > I'm using a CRUD framework called Tynamo, which in turn relies on Apache > Tapestry and Hibernate. This all works fine, except for when I try to use > it for CRUD on a table with a composite/compound primary key. > I've decided not to go the @EmbeddedId route, since it seems to not work > at all with the framework. That being said, I have been using the @IdClass > method, which is mostly working; I think I'm a line or two of code away > from success. > The issue is that when it starts using reflection to build the objects, it > blows up and says, > org.apache.tapestry5.ioc.internal.util.TapestryException, caused by > java.lang.NullPointerException at > org.apache.tapestry5.internal.hibernate.HibernateEntityValueEncoder.(HibernateEntityValueEncoder.java:51). > I honestly have no idea what's the deal here, but since I have normal > table CRUD operation working for numerous other tables, I would assume this > is somehow related to this table using a composite/compound primary key. > One thing I did try was to move the static inner class to its own package > and remove the staticclass modifier, but the exact same error occurred. > You can see my class below: > > package com.company.crud.entities; > > > > import java.io.Serializable; > > > > import javax.persistence.Column; > > import javax.persistence.Entity; > > import javax.persistence.Id; > > import javax.persistence.IdClass; > > > > import com.company.crud.entities.TransferExtension.TransferExtensionPK; > > > > @Entity(name = "Transfer_Extensions") > > @IdClass(TransferExtensionPK.class) > > public class TransferExtension implements Serializable { > > private static final long serialVersionUID = 1L; > > > > @Id > > // @NotNull(message = "Please supply a Script Code") > > // @Length(min = 3, max = 4) > > @Column(name = "Division", nullable = false) > > private String scriptCode; > > > > @Id > > // @NotNull(message = "Please supply a Transfer Type") > > // @Length(min = 3, max = 6) > > @Column(name = "Transfer_Type", nullable = false) > > private String transferType; > > > > @Column(name = "Extension", nullable = true) > > private String englishExtension; > > > > @Column(name = "Span_Extension", nullable = true) > > private String spanishExtension; > > > > @Column(name = "Call_Type", nullable = true) > > private String callType; > > > > @Column(name = "Call_Center", nullable = true) > > private String callCenter; > > > > public TransferExtension() { > > } > > > > public TransferExtension(String scriptCode, String transferType, > > String englishExtension, String spanishExtension, String > callType, > > String callCenter) { > > > > this.callCenter = callCenter; > > this.callType = callType; > > this.englishExtension = englishExtension; > > this.scriptCode = scriptCode; > > this.spanishExtension = spanishExtension; > > this.transferType = transferType; > > } > > > > public String getScriptCode() { > > return this.scriptCode; > > } > > > > public void setScriptCode(String scriptCode) { > > this.scriptCode = scriptCode; > > } > > > > public String getTransferType() { > > return this.transferType; > > } > > > > public void setTransferType(String transferType) { > > this.transferType = transferType; > > } > > > > public String getEnglishExtension() { > > return this.englishExtension; > > } > > > > public void setEnglishExtension(String englishExtension) { > > this.englishExtension = englishExtension; > > } > > > > public String getSpanishExtension() { > > return this.spanishExtension; > > } > > > > public void setSpanishExtension(String spanishExtension) { > > this.spanishExtension = spanishExtension; > > } > > > > public String getCallType() { > > return this.callType; > > } > > > > public void setCallType(String callType) { > > this.callType = callType; > > } > > > > public Str
Re: HibernateEntityValueEncoder NullPointerException - Composite/Compund Primary Key Issue
On Tue, 20 Jan 2015 17:43:35 -0200, Witt, Aaron wrote: Hi Tapestry Users, Hi! I'm using a CRUD framework called Tynamo, which in turn relies on Apache Tapestry and Hibernate. This all works fine, except for when I try to use it for CRUD on a table with a composite/compound primary key. The tapestry-hibernate's provided ValueEncoder for entities doesn't support composite primary keys. Unless you're dealing with legacy databases, in my humble opinion, a composite primary key is always a very bad choice. I've decided not to go the @EmbeddedId route, since it seems to not work at all with the framework. That being said, I have been using the @IdClass method, which is mostly working; I think I'm a line or two of code away from success. The issue is that when it starts using reflection to build the objects, it blows up and says, org.apache.tapestry5.ioc.internal.util.TapestryException, caused by java.lang.NullPointerException at org.apache.tapestry5.internal.hibernate.HibernateEntityValueEncoder.(HibernateEntityValueEncoder.java:51). I honestly have no idea what's the deal here, but since I have normal table CRUD operation working for numerous other tables, I would assume this is somehow related to this table using a composite/compound primary key. One thing I did try was to move the static inner class to its own package and remove the staticclass modifier, but the exact same error occurred. You can see my class below: package com.company.crud.entities; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; import com.company.crud.entities.TransferExtension.TransferExtensionPK; @Entity(name = "Transfer_Extensions") @IdClass(TransferExtensionPK.class) public class TransferExtension implements Serializable { private static final long serialVersionUID = 1L; @Id // @NotNull(message = "Please supply a Script Code") // @Length(min = 3, max = 4) @Column(name = "Division", nullable = false) private String scriptCode; @Id // @NotNull(message = "Please supply a Transfer Type") // @Length(min = 3, max = 6) @Column(name = "Transfer_Type", nullable = false) private String transferType; @Column(name = "Extension", nullable = true) private String englishExtension; @Column(name = "Span_Extension", nullable = true) private String spanishExtension; @Column(name = "Call_Type", nullable = true) private String callType; @Column(name = "Call_Center", nullable = true) private String callCenter; public TransferExtension() { } public TransferExtension(String scriptCode, String transferType, String englishExtension, String spanishExtension, String callType, String callCenter) { this.callCenter = callCenter; this.callType = callType; this.englishExtension = englishExtension; this.scriptCode = scriptCode; this.spanishExtension = spanishExtension; this.transferType = transferType; } public String getScriptCode() { return this.scriptCode; } public void setScriptCode(String scriptCode) { this.scriptCode = scriptCode; } public String getTransferType() { return this.transferType; } public void setTransferType(String transferType) { this.transferType = transferType; } public String getEnglishExtension() { return this.englishExtension; } public void setEnglishExtension(String englishExtension) { this.englishExtension = englishExtension; } public String getSpanishExtension() { return this.spanishExtension; } public void setSpanishExtension(String spanishExtension) { this.spanishExtension = spanishExtension; } public String getCallType() { return this.callType; } public void setCallType(String callType) { this.callType = callType; } public String getCallCenter() { return this.callCenter; } public void setCallCenter(String callCenter) { this.callCenter = callCenter; } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("TransferExtension [scriptCode=") .append(this.scriptCode).append(", transferType=") .append(this.transferType).append(", englishExtension=") .append(this.englishExtension).append(", spanishExtension=") .append(this.spanishExtension).append(", callType=") .append(this.callType).append(", callCenter=") .append(this.callCenter).append("]"); return builder.toString(); } public static class TransferExtensionPK impl
HibernateEntityValueEncoder NullPointerException - Composite/Compund Primary Key Issue
Hi Tapestry Users, I'm using a CRUD framework called Tynamo, which in turn relies on Apache Tapestry and Hibernate. This all works fine, except for when I try to use it for CRUD on a table with a composite/compound primary key. I've decided not to go the @EmbeddedId route, since it seems to not work at all with the framework. That being said, I have been using the @IdClass method, which is mostly working; I think I'm a line or two of code away from success. The issue is that when it starts using reflection to build the objects, it blows up and says, org.apache.tapestry5.ioc.internal.util.TapestryException, caused by java.lang.NullPointerException at org.apache.tapestry5.internal.hibernate.HibernateEntityValueEncoder.(HibernateEntityValueEncoder.java:51). I honestly have no idea what's the deal here, but since I have normal table CRUD operation working for numerous other tables, I would assume this is somehow related to this table using a composite/compound primary key. One thing I did try was to move the static inner class to its own package and remove the staticclass modifier, but the exact same error occurred. You can see my class below: package com.company.crud.entities; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; import com.company.crud.entities.TransferExtension.TransferExtensionPK; @Entity(name = "Transfer_Extensions") @IdClass(TransferExtensionPK.class) public class TransferExtension implements Serializable { private static final long serialVersionUID = 1L; @Id // @NotNull(message = "Please supply a Script Code") // @Length(min = 3, max = 4) @Column(name = "Division", nullable = false) private String scriptCode; @Id // @NotNull(message = "Please supply a Transfer Type") // @Length(min = 3, max = 6) @Column(name = "Transfer_Type", nullable = false) private String transferType; @Column(name = "Extension", nullable = true) private String englishExtension; @Column(name = "Span_Extension", nullable = true) private String spanishExtension; @Column(name = "Call_Type", nullable = true) private String callType; @Column(name = "Call_Center", nullable = true) private String callCenter; public TransferExtension() { } public TransferExtension(String scriptCode, String transferType, String englishExtension, String spanishExtension, String callType, String callCenter) { this.callCenter = callCenter; this.callType = callType; this.englishExtension = englishExtension; this.scriptCode = scriptCode; this.spanishExtension = spanishExtension; this.transferType = transferType; } public String getScriptCode() { return this.scriptCode; } public void setScriptCode(String scriptCode) { this.scriptCode = scriptCode; } public String getTransferType() { return this.transferType; } public void setTransferType(String transferType) { this.transferType = transferType; } public String getEnglishExtension() { return this.englishExtension; } public void setEnglishExtension(String englishExtension) { this.englishExtension = englishExtension; } public String getSpanishExtension() { return this.spanishExtension; } public void setSpanishExtension(String spanishExtension) { this.spanishExtension = spanishExtension; } public String getCallType() { return this.callType; } public void setCallType(String callType) { this.callType = callType; } public String getCallCenter() { return this.callCenter; } public void setCallCenter(String callCenter) { this.callCenter = callCenter; } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("TransferExtension [scriptCode=") .append(this.scriptCode).append(", transferType=") .append(this.transferType).append(", englishExtension=") .append(this.englishExtension).append(", spanishExtension=") .append(this.spanishExtension).append(", callType=") .append(this.callType).append(", callCenter=") .append(this.callCenter).append("]"); return builder.toString(); } public static class TransferExtensionPK implements Serializable { private static final long serialVersionUID = 4L; private String scriptCode; private String transferType; public TransferExtensionPK() { } public TransferExtensionPK(String scriptCode, String transferType) { this.scriptCode = sc