Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Object Relational Mapping
ava.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
Baktha Elumalai
Ranch Hand
Posts: 48
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have 2 tables
Pojo class
Deviceanalogfeaturess.java
package pip; import java.io.Serializable; import java.util.Date; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; /** * * @author baktha */ @Entity @Table(name = "deviceanalogfeaturess") @NamedQueries({@NamedQuery(name = "Deviceanalogfeaturess.findAll", query = "SELECT d FROM Deviceanalogfeaturess d"), @NamedQuery(name = "Deviceanalogfeaturess.findById", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.id = :id"), @NamedQuery(name = "Deviceanalogfeaturess.findByClientId", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.clientId = :clientId"), @NamedQuery(name = "Deviceanalogfeaturess.findByObjectId", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.objectId = :objectId"), @NamedQuery(name = "Deviceanalogfeaturess.findByDevice", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.device = :device"), @NamedQuery(name = "Deviceanalogfeaturess.findByInput", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.input = :input"), @NamedQuery(name = "Deviceanalogfeaturess.findByInputSource", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.inputSource = :inputSource"), @NamedQuery(name = "Deviceanalogfeaturess.findByA0", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.a0 = :a0"), @NamedQuery(name = "Deviceanalogfeaturess.findByA1", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.a1 = :a1"), @NamedQuery(name = "Deviceanalogfeaturess.findByA2", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.a2 = :a2"), @NamedQuery(name = "Deviceanalogfeaturess.findByA3", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.a3 = :a3"), @NamedQuery(name = "Deviceanalogfeaturess.findByUnits", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.units = :units"), @NamedQuery(name = "Deviceanalogfeaturess.findByFormat", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.format = :format"), @NamedQuery(name = "Deviceanalogfeaturess.findByType", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.type = :type"), @NamedQuery(name = "Deviceanalogfeaturess.findByMin", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.min = :min"), @NamedQuery(name = "Deviceanalogfeaturess.findByMax", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.max = :max"), @NamedQuery(name = "Deviceanalogfeaturess.findByEncoding", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.encoding = :encoding"), @NamedQuery(name = "Deviceanalogfeaturess.findByAveraging", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.averaging = :averaging"), @NamedQuery(name = "Deviceanalogfeaturess.findByAverageNo", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.averageNo = :averageNo"), @NamedQuery(name = "Deviceanalogfeaturess.findByAverageSample", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.averageSample = :averageSample"), @NamedQuery(name = "Deviceanalogfeaturess.findByTimeStamp", query = "SELECT d FROM Deviceanalogfeaturess d WHERE d.timeStamp = :timeStamp")}) public class Deviceanalogfeaturess implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "Id") private Integer id; @Basic(optional = false) @Column(name = "ClientId") private int clientId; @Basic(optional = false) @Column(name = "ObjectId") private int objectId; @Basic(optional = false) @Column(name = "Device") private String device; @Basic(optional = false) @Column(name = "Input") private String input; @Basic(optional = false) @Column(name = "InputSource") private String inputSource; @Basic(optional = false) @Column(name = "A0") private double a0; @Basic(optional = false) @Column(name = "A1") private double a1; @Basic(optional = false) @Column(name = "A2") private double a2; @Basic(optional = false) @Column(name = "A3") private double a3; @Column(name = "Units") private String units; @Column(name = "Format") private String format; @Column(name = "Type") private Integer type; @Basic(optional = false) @Column(name = "Min") private double min; @Basic(optional = false) @Column(name = "Max") private double max; @Column(name = "Encoding") private String encoding; @Column(name = "Averaging") private Boolean averaging; @Column(name = "AverageNo") private Integer averageNo; @Column(name = "AverageSample") private Integer averageSample; @Basic(optional = false) @Column(name = "TimeStamp") @Temporal(TemporalType.TIMESTAMP) private Date timeStamp; public Deviceanalogfeaturess() { } public Deviceanalogfeaturess(Integer id) { this.id = id; } public Deviceanalogfeaturess(Integer id, int clientId, int objectId, String device, String input, String inputSource, double a0, double a1, double a2, double a3, double min, double max, Date timeStamp) { this.id = id; this.clientId = clientId; this.objectId = objectId; this.device = device; this.input = input; this.inputSource = inputSource; this.a0 = a0; this.a1 = a1; this.a2 = a2; this.a3 = a3; this.min = min; this.max = max; this.timeStamp = timeStamp; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public int getClientId() { return clientId; } public void setClientId(int clientId) { this.clientId = clientId; } public int getObjectId() { return objectId; } public void setObjectId(int objectId) { this.objectId = objectId; } public String getDevice() { return device; } public void setDevice(String device) { this.device = device; } public String getInput() { return input; } public void setInput(String input) { this.input = input; } public String getInputSource() { return inputSource; } public void setInputSource(String inputSource) { this.inputSource = inputSource; } public double getA0() { return a0; } public void setA0(double a0) { this.a0 = a0; } public double getA1() { return a1; } public void setA1(double a1) { this.a1 = a1; } public double getA2() { return a2; } public void setA2(double a2) { this.a2 = a2; } public double getA3() { return a3; } public void setA3(double a3) { this.a3 = a3; } public String getUnits() { return units; } public void setUnits(String units) { this.units = units; } public String getFormat() { return format; } public void setFormat(String format) { this.format = format; } public Integer getType() { return type; } public void setType(Integer type) { this.type = type; } public double getMin() { return min; } public void setMin(double min) { this.min = min; } public double getMax() { return max; } public void setMax(double max) { this.max = max; } public String getEncoding() { return encoding; } public void setEncoding(String encoding) { this.encoding = encoding; } public Boolean getAveraging() { return averaging; } public void setAveraging(Boolean averaging) { this.averaging = averaging; } public Integer getAverageNo() { return averageNo; } public void setAverageNo(Integer averageNo) { this.averageNo = averageNo; } public Integer getAverageSample() { return averageSample; } public void setAverageSample(Integer averageSample) { this.averageSample = averageSample; } public Date getTimeStamp() { return timeStamp; } public void setTimeStamp(Date timeStamp) { this.timeStamp = timeStamp; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Deviceanalogfeaturess)) { return false; } Deviceanalogfeaturess other = (Deviceanalogfeaturess) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "pip.Deviceanalogfeaturess[id=" + id + "]"; } }
Fuelrecord.java
package pip; import java.io.Serializable; import java.util.Set; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; /** * * @author baktha */ @Entity @Table(name = "fuelrecord") /* @NamedQueries({@NamedQuery(name = "Fuelrecord.findAll", query = "SELECT f FROM Fuelrecord f"), @NamedQuery(name = "Fuelrecord.findById", query = "SELECT f FROM Fuelrecord f WHERE f.id = :id"), @NamedQuery(name = "Fuelrecord.findByObjectId", query = "SELECT f FROM Fuelrecord f WHERE f.objectId = :objectId"), @NamedQuery(name = "Fuelrecord.findByMinValue", query = "SELECT f FROM Fuelrecord f WHERE f.minValue = :minValue")}) */ public class Fuelrecord implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "Id") private Integer id; @Column(name = "ObjectId") private Integer objectId; @Column(name = "MinValue") private Integer minValue; public Fuelrecord() { } public Fuelrecord(Integer id) { this.id = id; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getObjectId() { return objectId; } public void setObjectId(Integer objectId) { this.objectId = objectId; } public Integer getMinValue() { return minValue; } public void setMinValue(Integer minValue) { this.minValue = minValue; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Fuelrecord)) { return false; } Fuelrecord other = (Fuelrecord) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "pip.Fuelrecord[id=" + id + "]"; } }
main files
Iterator query = session.createSQLQuery("select {d.*}, {f.*} from deviceanalogfeaturess d inner join fuelrecord f on d.ObjectId=f.ObjectId where d.ObjectId= '" + ObjectId + "'").addEntity("d", Deviceanalogfeaturess.class) .addEntity("f", Fuelrecord.class).list().iterator(); [color=blue] Deviceanalogfeaturess d =(Deviceanalogfeaturess)query.next(); [/color] analog = d.getObjectId(); Fuelrecord f =(Fuelrecord)query.next(); cdiff = f.getMinValue();
I got the following error
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to pip.Deviceanalogfeaturess
Regards
Bakthavachalam E
Craig Taylor
Ranch Hand
Posts: 64
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Your query is selecting both classes ... you are actually getting back an array with [0] containing Deviceanalogfeaturess and [1] containing the Fuelrecord.
The correct code would be something along the lines of :
Iterator query = session.createSQLQuery("select {d.*}, {f.*} from deviceanalogfeaturess d inner join fuelrecord f on d.ObjectId=f.ObjectId where d.ObjectId= '" + ObjectId + "'").addEntity("d", Deviceanalogfeaturess.class) .addEntity("f", Fuelrecord.class).list().iterator(); Object[] row = query.next(); Deviceanalogfeaturess d =(Deviceanalogfeaturess) row[0]; Fuelrecord f =(Fuelrecord)row[1];
Baktha Elumalai
Ranch Hand
Posts: 48
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
thanks for your reply
i change something regarding your reply
like this
Iterator query = session.createSQLQuery("select {d.*}, {f.*} from deviceanalogfeaturess d join fuelrecord f on d.objectId=f.objectId where d.objectId= '" + ObjectId + "'").addEntity("d", Deviceanalogfeaturess.class) .addEntity("f", Fuelrecord.class).list().iterator(); // rs3 = st.executeQuery("select navl.deviceanalogfeatures.ObjectId,navl.fuelrecord.MinValue from navl.deviceanalogfeatures // inner join navl.fuelrecord on navl.deviceanalogfeatures.ObjectId = navl.fuelrecord.ObjectId // where navl.deviceanalogfeatures.ObjectId='" + ObjectId + "'"); while (query.hasNext()) { Object[] row = (Object[]) query.next(); Deviceanalogfeaturess d =(Deviceanalogfeaturess) row[0]; analog = d.getObjectId(); Fuelrecord f =(Fuelrecord)row[1]; cdiff = f.getMinValue(); } System.out.println("ObjectId" +analog); System.out.println("Minvalue" +analog);
but the valur printed both as same
ObjectId 18
Minvalue 18
but in our case Minvalue from fuelrecord is 10 but it will print only 18
hoe to solve this one
please help me
Regards
Bakthavachalam E
Baktha Elumalai
Ranch Hand
Posts: 48
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
sorry this is my mistake
i changed
Iterator query = session.createSQLQuery("select {d.*}, {f.*} from deviceanalogfeaturess d join fuelrecord f on d.objectId=f.objectId where d.objectId= '" + ObjectId + "'").addEntity("d", Deviceanalogfeaturess.class).addEntity("f", Fuelrecord.class).list().iterator();
// rs3 = st.executeQuery("select navl.deviceanalogfeatures.ObjectId,navl.fuelrecord.MinValue from navl.deviceanalogfeatures inner join navl.fuelrecord on navl.deviceanalogfeatures.ObjectId = navl.fuelrecord.ObjectId where navl.deviceanalogfeatures.ObjectId='" + ObjectId + "'");
while (query.hasNext())
{
Object[] row = (Object[]) query.next();
Deviceanalogfeaturess d =(Deviceanalogfeaturess) row[0];
analog = d.getObjectId();
Fuelrecord f =(Fuelrecord)row[1];
cdiff = f.getMinValue();
}
System.out.println("ObjectId" +analog);
System.out.println("Minvalue" +cdiff);
System.out.println("Minvalue" +analog); changed to System.out.println("Minvalue" +cdiff);
Now it's work fine
thanks for your reply
Regards
Bakthavachalam E
Ulf Dittmer
Rancher
Posts: 43081
77
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Guys, in the future please make sure to add linebreaks to code you post - not everyone has 3 feet wide screens.
Baktha Elumalai
Ranch Hand
Posts: 48
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
sorry for my mistake
In future defiantly i add line breaks
Regards
Bakthavachalam E
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Inner join problem
Sequence increment does not match its pre-allocation size.
org.hibernate.QueryException: could not resolve property: ObjectId of: test.Objtablee
Can't use Optimistic Locking
Trying to figure out how to use MySQL and generated @Id
More...