Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

sura watthana

Ranch Hand
+ Follow
since Sep 13, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sura watthana

What is the name of the object that is created/maintained by the Servlet Container and contains all context information about the whole Web application? This object can be used as a memory cache.
10 years ago
Scenario is: let's say a user submits a request to purchase a book from an online book store. response was slow due to ... .
the user thought the web app didn't get the request. the user clicks submit button again. now the web app receives the exact same
request twice.

is there a way to make a java web app to deal with multiple duplicate requests sent by user?
in other word, how to make a java web app idempotent?
10 years ago
Scenario is: let's say a user submits a request to purchase a book from an online book store. response was slow due to ... .
the user thought the web app didn't get the request. the user clicks submit button again. now the web app receives the exact same
request twice.

is there a way to make a java web app to deal with multiple duplicate requests sent by user?
in other word, how to make a java web app idempotent?
Are static variable and method threadsafe? if so Could you explain with some samples?
Are static variable and method threadsafe? if so why? Could you explain with some samples?
10 years ago
hi,

looking at the class below


I don't understand how it is possible that p.name can be directly access even though name is a private instance variable.
anyone knows an explanation to this?

thanks

sura
12 years ago
thank you greg.
12 years ago
Hi,

I'm wondering how PriorityQueue works with natural order of String. Does it use hashcode of String to determine the order?
anyone knows answer to this? please

thank you

sura

12 years ago
HI,

don't worry I think I know what he's trying to say about Service Provider framework. thank you so much

cheers,

sura
12 years ago
Hi,

I'm reading the effective java book on the very first item. When it comes to the third advantage of using static factory methods, I got lost.
could someone elaborate? thank you so much.


cheers,

sura
12 years ago
hi,

just out of curiosity, i'd like to know why one cannot make a call to an instance method, or access an instance variable, until after the super constructor runs.
if anyone could answer me this, that'd be great.

cheers,

sura
Hi,
something is bothering me, hope you can help answering this.
we all know that an enum can be declared inside or outside a class.
just out of curiosity why can't a enum be declared in a method?

cheers,

sura


hi,

referring to the code in previous topic,
i'm almost done with the many-to-many association but
this elt field just popped up out of no where

here is the code I ran


here is the stack trace
Hibernate: insert into students (name) values (?)
Hibernate: insert into teachers (name) values (?)
Hibernate: insert into teachers_students (teacher_id, elt) values (?, ?)
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:145)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.oxman.test.StudentTeacherTest.main(StudentTeacherTest.java:34)
Caused by: java.sql.BatchUpdateException: Unknown column 'elt' in 'field list'
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1669)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1085)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 8 more


so if anyone has any idea what went wrong please let me know
thank you so much

Sura
Hi

I am new to Hibernate. I am trying to implement a many-to-many association.
I have a simple scenario where I have two entities three tables.
one is Teacher.java with teacher table containg id and name.
the other is Student.java with student table containing id and name as well.

let me show you my java files, my tables and the hibernate mapping files.





<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.oxman.entity.Teacher" table="teachers">
<id name="id" column="uid" type="int" unsaved-value="null">
<generator class="native"/>
</id>
<property name="name" type="string" length="255"/>
<set name="students" table="teachers_students" cascade="all">
<key column="teacher_id"/>
<many-to-many class="com.oxman.entity.Student"/>
</set>
</class>
</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.oxman.entity.Student" table="students">
<id name="id" column="uid" type="int" unsaved-value="null">
<generator class="native"/>
</id>
<property name="name" type="string" length="255"/>
<set name="teachers" table="teachers_students" cascade="all">
<key column="student_id"/>
<many-to-many class="com.oxman.entity.Teacher"/>
</set>
</class>
</hibernate-mapping>



DROP TABLE IF EXISTS `teachers`;
CREATE TABLE `teachers` (
`uid` int(11) NOT NULL auto_increment,
`name` varchar(255) default NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `students`;
CREATE TABLE `students` (
`uid` int(11) NOT NULL auto_increment,
`name` varchar(255) default NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `teachers_students`;
CREATE TABLE `teachers_students` (
`teacher_id` int(11) NOT NULL default '0',
`student_id` int(11) NOT NULL default '0',
PRIMARY KEY (`teacher_id`,`student_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;




I have tried to run this code


I need to tell you that both student and teacher do exist in the database.

Here is the Exception stack trace
Hibernate: select teacher0_.uid as uid4_0_, teacher0_.name as name4_0_ from teachers teacher0_ where teacher0_.uid=?
Hibernate: select students0_.teacher_id as teacher1_0_, students0_.elt as elt0_ from teachers_students students0_ where students0_.teacher_id=?
org.hibernate.exception.SQLGrammarException:
could not initialize a collection: [com.oxman.entity.Teacher.students#6]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2001)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:797)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:241)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3044)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:395)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:195)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at com.oxman.test.StudentTeacherTest.main(StudentTeacherTest.java:26)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'students0_.elt' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1031)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3376)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3308)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1837)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2543)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1737)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1888)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
... 20 more



Does anybody have any idea what elt field is and why does it appear here?

thank you

Sura