I'm having a tough time figuring out the issue with Serialization in hadoop. Here's my class -
public class CrawlerTweet implements Serializable, Writable {
private static final long serialVersionUID = 1L;
private String keywords;
private List<TweetStatus> tweets;
private long queryTime = 0;
public CrawlerTweet() {}
public CrawlerTweet(String keys, List<TweetStatus> tweets, long queryTime){
this.keywords = keys;
this.tweets = tweets;
this.queryTime = queryTime;
}
public static CrawlerTweet read(DataInput in) throws IOException {
CrawlerTweet ts= new CrawlerTweet();
ts.readFields(in);
return ts;
}
#Override
public void readFields(DataInput din) throws IOException {
queryTime = din.readLong();
keywords = din.readLine();
tweets.clear();
IntWritable size = new IntWritable();
size.readFields(din);
int n = size.get();
while(n -- > 0) {
TweetStatus ts = new TweetStatus();
ts.readFields(din);
tweets.add(ts);
}
}
#Override
public void write(DataOutput dout) throws IOException {
dout.writeChars(keywords);
dout.writeLong(queryTime);
IntWritable size = new IntWritable(tweets.size());
size.write(dout);
for (TweetStatus ts : tweets)
ts.write(dout);
}
public String getKeywords(){
return keywords;
}
public List<TweetStatus> getTweets(){
return tweets;
}
public long getQueryTime(){
return queryTime;
}
}
If I implment both Serizable n WRitable interfaces, I get following exception,
java.lang.ClassNotFoundException: mydat.twitter.dto.CrawlerTweet
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:601)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1572)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1493)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1729)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1326)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
at focusedCrawler.util.storage.socket.ServerConnectionHandler.buildRequestObject(ServerConnectionHandler.java:136)
at focusedCrawler.util.storage.socket.ServerConnectionHandler.run(ServerConnectionHandler.java:340)
And, if I implment Writable only, I get NotSerializableException -
Erro de comunicacao: bigdat.twitter.dto.CrawlerTweet
Dormindo 5 mls
`[21/JUN/2013:11:23:39] [SocketAdapterFactory] [produce] [hadoop22:3190]
Erro de comunicacao: bigdat.twitter.dto.CrawlerTweet
java.io.NotSerializableException: bigdat.twitter.dto.CrawlerTweet
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330)
at focusedCrawler.util.storage.socket.StorageRemoteAdapter.serializeParamObject(StorageRemoteAdapter.java:113)
at focusedCrawler.util.storage.socket.StorageRemoteAdapter.defaultMethod(StorageRemoteAdapter.java:205)
at focusedCrawler.util.storage.socket.StorageRemoteAdapter.insert(StorageRemoteAdapter.java:289)
at focusedCrawler.util.storage.distribution.StorageRemoteAdapterReconnect.insert(StorageRemoteAdapterReconnect.java:213)
at bigdat.twitter.crawler.CrawlTwitter.download(Unknown Source)
at bigdat.twitter.crawler.CrawlTwitter.run(Unknown Source)
Further information extracted from comments:
CrawlerTweet is packaged in BDAnalytics16.jar file.
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:/home/rgupta/bdAnalytics/lib/*
hadoop jar $jarpath/BDAnalytics16.jar bigdat.twitter.crawler.CrawlTwitter \
$crwlInputFile > $logsFldr/crawler_$1.log 2>&1 &
Help will be much appreciated!
Thx!
Related
I have a usecase where my Ignite cache key/value cannot have corresponding Java class, I am using BinaryObject as key and value type. Below code works fine (without any readthrough).
CacheConfiguration cfg = new CacheConfiguration("cache1");
IgniteCache<BinaryObject, BinaryObject> cache1 = ignite.getOrCreateCache(cfg).withKeepBinary();
cache1.put(createBOKey("mykey", "k1"), createBOVal());
cache1.put(createBOKey("mykey", "k2"), createBOVal());
cache1.put(createBOKey("mykey", "k3"), createBOVal());
Object v1 = cache1.get(createBOKey("mykey", "k1"));
System.out.println("**** cache1 key " + v1); // shows value
Object v2 = cache1.get(createBOKey("mykey", "k10"));
System.out.println("**** cache1 key " + v2); // show null
BinaryObject createBOKey(String k, String v) {
BinaryObjectBuilder builder = ignite.binary().builder("key-type1");
builder.setField(k, v);
return builder.build();
}
BinaryObject createBOVal() {
BinaryObjectBuilder builder = ignite.binary().builder("value-type1");
builder.setField(fieldName("cache1", "f1"), "hello");
builder.setField(fieldName("cache1", "f2"), 10.75);
return builder.build();
}
Now as soon as I enable readThrough for this cache it starts failing for cache miss cases.
cfg.setReadThrough(true);
cfg.setCacheLoaderFactory(new Factory<CacheLoader<BinaryObject, BinaryObject>>() {
#Override
public CacheLoader<BinaryObject, BinaryObject> create() {
return new CacheLoader<BinaryObject, BinaryObject>() {
#Override
public BinaryObject load(BinaryObject obj) throws CacheLoaderException {
System.out.println("**** Loading from backingstore " + obj);
return null;
}
#Override
public Map<BinaryObject, BinaryObject> loadAll(Iterable<? extends BinaryObject> arg0) throws CacheLoaderException {
return null;
}
};
}
});
On cache miss it throw below exceptions and not even reaches cacheloader.load().
Exception in thread "main" javax.cache.CacheException: class org.apache.ignite.IgniteCheckedException: key-type1
at org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils.java:1317)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.cacheException(IgniteCacheProxyImpl.java:2066)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.get(IgniteCacheProxyImpl.java:1093)
at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.get(GatewayProtectedCacheProxy.java:676)
at com.basit.bo.btree.TestBinaryTreeMapKey.main(TestBinaryTreeMapKey.java:74)
Caused by: class org.apache.ignite.IgniteCheckedException: key-type1
at org.apache.ignite.internal.util.IgniteUtils.cast(IgniteUtils.java:7507)
at org.apache.ignite.internal.processors.closure.GridClosureProcessor$2.body(GridClosureProcessor.java:975)
at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:120)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: class org.apache.ignite.binary.BinaryInvalidTypeException: key-type1
at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:762)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize0(BinaryReaderExImpl.java:1757)
at org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1716)
at org.apache.ignite.internal.binary.BinaryObjectImpl.deserializeValue(BinaryObjectImpl.java:792)
at org.apache.ignite.internal.binary.BinaryObjectImpl.value(BinaryObjectImpl.java:142)
at org.apache.ignite.internal.processors.cache.CacheObjectUtils.unwrapBinary(CacheObjectUtils.java:176)
at org.apache.ignite.internal.processors.cache.CacheObjectUtils.unwrapBinaryIfNeeded(CacheObjectUtils.java:67)
at org.apache.ignite.internal.processors.cache.CacheObjectContext.unwrapBinaryIfNeeded(CacheObjectContext.java:136)
at org.apache.ignite.internal.processors.cache.GridCacheContext.unwrapBinaryIfNeeded(GridCacheContext.java:1808)
at org.apache.ignite.internal.processors.cache.GridCacheContext.unwrapBinaryIfNeeded(GridCacheContext.java:1796)
at org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter.loadFromStore(GridCacheStoreManagerAdapter.java:314)
at org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter.load(GridCacheStoreManagerAdapter.java:293)
at org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter.loadAllFromStore(GridCacheStoreManagerAdapter.java:434)
at org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter.loadAll(GridCacheStoreManagerAdapter.java:400)
at org.apache.ignite.internal.processors.cache.GridCacheAdapter$18.call(GridCacheAdapter.java:2225)
at org.apache.ignite.internal.processors.cache.GridCacheAdapter$18.call(GridCacheAdapter.java:2223)
at org.apache.ignite.internal.processors.cache.GridCacheContext$3.call(GridCacheContext.java:1479)
at org.apache.ignite.internal.util.IgniteUtils.wrapThreadLoader(IgniteUtils.java:7005)
at org.apache.ignite.internal.processors.closure.GridClosureProcessor$2.body(GridClosureProcessor.java:967)
... 4 more
Caused by: java.lang.ClassNotFoundException: key-type1
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at org.apache.ignite.internal.util.IgniteUtils.forName(IgniteUtils.java:8828)
at org.apache.ignite.internal.MarshallerContextImpl.getClass(MarshallerContextImpl.java:324)
at org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:753)
... 22 more
You should also set storeKeepBinary to true.
I've generated a Spring Boot web application using Spring Initializer, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file.
Technologies used:
Spring Boot 1.4.2.RELEASE, Spring 4.3.4.RELEASE, Thymeleaf 2.1.5.RELEASE, Tomcat Embed 8.5.6, Maven 3, Java 8
I have this classes
public class DeviceEvent {
public DeviceEvent(Device device) {
this.device = device;
}
private Device device;
private Long id;
private Double latitude;
private Double longitude;
private Date dateReceived;
private String message;
private Float rssi;
private Integer battery;
private Boolean alarm;
private Boolean processed;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
public Date getDateReceived() {
return dateReceived;
}
public void setDateReceived(Date dateReceived) {
this.dateReceived = dateReceived;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Float getRssi() {
return rssi;
}
public void setRssi(Float rssi) {
this.rssi = rssi;
}
public Integer getBattery() {
return battery;
}
public void setBattery(Integer battery) {
this.battery = battery;
}
public Boolean getAlarm() {
return alarm;
}
public void setAlarm(Boolean alarm) {
this.alarm = alarm;
}
public Boolean getProcessed() {
return processed;
}
public void setProcessed(Boolean processed) {
this.processed = processed;
}
}
but I got this error executing this test:
Device device = new Device("C380F");
DeviceEvent deviceEvent = new DeviceEvent(device);
deviceEvent.setId(Sequencer.getNextVal());
deviceEvent.setAlarm(Boolean.FALSE);
deviceEvent.setBattery(78);
deviceEvent.setDateReceived(new Date());
deviceEvent.setLatitude(50.834015);
deviceEvent.setLongitude(4.377885);
deviceEvent.setMessage("FAKE_MSG");
deviceEvent.setProcessed(Boolean.FALSE);
deviceEvent.setRssi((float)80);
repository.insert(deviceEvent);
...
#Override
public long insert(DeviceEvent newDeviceEvent) {
long id = Sequencer.getNextVal();
int numOfRowsAffected = jdbcTemplate.update(
"insert into T_DEVICE_EVENT (ID, DEVICE_ID, LATITUDE, LONGITUDE, MESSAGE, DATE_RECEIVED, RSSI, BATTERY, ALARM, PROCESSED) " +
" values (?,?,?,?,?,?,?,?,?,?);",
id,
newDeviceEvent.getDevice().getId(),
newDeviceEvent.getLatitude(),
newDeviceEvent.getLongitude(),
newDeviceEvent.getMessage(),
newDeviceEvent.getRssi(),
newDeviceEvent.getBattery(),
newDeviceEvent.getAlarm(),
0);
if (numOfRowsAffected==1) return id;
else return -1;
}
..
the table
CREATE TABLE IF NOT EXISTS t_device_event (
id bigint PRIMARY KEY,
device_id bigint NOT NULL,
latitude decimal NULL,
longitude decimal NULL,
message varchar(100) ,
date_received timestamp,
rssi float,
battery int,
alarm boolean,
processed boolean,
FOREIGN KEY (device_id) REFERENCES public.t_device(id));
the error:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [insert into T_DEVICE_EVENT (ID, DEVICE_ID, LATITUDE, LONGITUDE, MESSAGE, DATE_RECEIVED, RSSI, BATTERY, ALARM, PROCESSED) values (?,?,?,?,?,?,?,?,?,?);]; nested exception is java.sql.SQLSyntaxErrorException: incompatible data type in conversion
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:91)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:649)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:870)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:931)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:941)
at com.ideefecloud.iot.repository.JdbcDeviceEventRepository.insert(JdbcDeviceEventRepository.java:44)
at com.ideefecloud.iot.repository.JdbcDeviceEventRepositoryTests.testInsert(JdbcDeviceEventRepositoryTests.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.sql.SQLSyntaxErrorException: incompatible data type in conversion
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.throwError(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.setParameter(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.setObject(Unknown Source)
at org.springframework.jdbc.core.StatementCreatorUtils.setValue(StatementCreatorUtils.java:454)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValueInternal(StatementCreatorUtils.java:238)
at org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(StatementCreatorUtils.java:169)
at org.springframework.jdbc.core.ArgumentPreparedStatementSetter.doSetValue(ArgumentPreparedStatementSetter.java:66)
at org.springframework.jdbc.core.ArgumentPreparedStatementSetter.setValues(ArgumentPreparedStatementSetter.java:47)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:875)
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:870)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633)
... 34 more
Caused by: org.hsqldb.HsqlException: incompatible data type in conversion
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.types.DateTimeType.convertJavaToSQL(Unknown Source)
... 44 more
I think your columns/parameters are misaligned. The date_received specifically doesn't seem to have a corresponding parameter so it's trying to convert a float (RSSI) into a timestamp
I am trying to deploy my application in WAS 8.5 server, but I see something very weired happending.
When I use the below jar while building , the application builds along with my wsdl without any issue. But it fails during deployment in WAS 8.5 server.
WAS 8.5.5.3 is using jdk 1.6.0.
Dependency used:
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>provided</scope>
</dependency>
My investigation conclude that the wsdl generated from the Endpoint Service during maven build needs the validation api but have to keep the scope as provided, as this jars are
provided by WAS server at runtime.
The above configuration gives the below error.
[7/24/16 10:10:25:501 IST] 00000063 WASWSDLGenera E WSWS7054E: The Web Services Description Language (WSDL) file could not be generated for the com.hex.rbm.erds.ws.endpoint.impl.EntitySearchServiceEndpoint Web service implementation class because of the following error: java.lang.ArrayStoreException
[7/24/16 10:10:25:507 IST] 00000063 WSModuleDescr E WSWS7027E: JAX-WS Service Descriptions could not be correctly built because of the following error: javax.xml.ws.WebServiceException: WSWS7054E: The Web Services Description Language (WSDL) file could not be generated for the com.hex.rbm.erds.ws.endpoint.impl.EntitySearchServiceEndpoint Web service implementation class because of the following error: java.lang.ArrayStoreException
at com.ibm.ws.websvcs.wsdl.WASWSDLGenerator.generateWsdl(WASWSDLGenerator.java:268)
at org.apache.axis2.jaxws.description.impl.EndpointDescriptionImpl.generateWSDL(EndpointDescriptionImpl.java:2084)
at org.apache.axis2.jaxws.description.impl.EndpointDescriptionImpl.<init>(EndpointDescriptionImpl.java:449)
at org.apache.axis2.jaxws.description.impl.ServiceDescriptionImpl.<init>(ServiceDescriptionImpl.java:401)
at org.apache.axis2.jaxws.description.impl.ServiceDescriptionImpl.<init>(ServiceDescriptionImpl.java:297)
at org.apache.axis2.jaxws.description.impl.DescriptionFactoryImpl.createServiceDescriptionFromDBCMap(DescriptionFactoryImpl.java:277)
at org.apache.axis2.jaxws.description.DescriptionFactory.createServiceDescriptionFromDBCMap(DescriptionFactory.java:524)
at com.ibm.ws.websvcs.desc.WSModuleDescriptorImpl.buildJAXWSServices(WSModuleDescriptorImpl.java:1345)
at com.ibm.ws.websvcs.desc.WSModuleDescriptorImpl._containsJAXWSWebServices(WSModuleDescriptorImpl.java:519)
at com.ibm.ws.websvcs.desc.WSModuleDescriptorImpl.containsJAXWSWebServices(WSModuleDescriptorImpl.java:494)
at com.ibm.ws.websvcs.deploy.WSCacheWriter.writeModuleCache(WSCacheWriter.java:571)
at com.ibm.ws.websvcs.deploy.WSCacheWriter.writeApplicationCache(WSCacheWriter.java:242)
at com.ibm.ws.websvcs.deploy.WSCacheWriter.writeApplicationCache(WSCacheWriter.java:167)
at com.ibm.ws.websvcs.deploy.PersistentStorageInstallSaveTask.performTask(PersistentStorageInstallSaveTask.java:196)
at com.ibm.ws.management.application.sync.AppBinaryProcessor$ExpandApp.expand(AppBinaryProcessor.java:1711)
at com.ibm.ws.management.application.sync.AppBinaryProcessor.postProcessSynchronousExt(AppBinaryProcessor.java:751)
at com.ibm.ws.management.bla.sync.BLABinaryProcessor.postProcess(BLABinaryProcessor.java:599)
at com.ibm.ws.management.bla.sync.BLABinaryProcessor.onChangeCompletion(BLABinaryProcessor.java:476)
at com.ibm.ws.management.bla.sync.BinaryProcessorWrapper.onChangeCompletion(BinaryProcessorWrapper.java:109)
at com.ibm.ws.management.repository.FileRepository.postNotify(FileRepository.java:1938)
at com.ibm.ws.management.repository.FileRepository.update(FileRepository.java:1442)
at com.ibm.ws.management.repository.client.LocalConfigRepositoryClient.update(LocalConfigRepositoryClient.java:189)
at com.ibm.ws.sm.workspace.impl.WorkSpaceMasterRepositoryAdapter.update(WorkSpaceMasterRepositoryAdapter.java:665)
at com.ibm.ws.sm.workspace.impl.RepositoryContextImpl.update(RepositoryContextImpl.java:1998)
at com.ibm.ws.sm.workspace.impl.RepositoryContextImpl.synch(RepositoryContextImpl.java:1946)
at com.ibm.ws.sm.workspace.impl.WorkSpaceImpl.synch(WorkSpaceImpl.java:549)
at com.ibm.ws.console.core.action.SyncWorkSpaceAction.execute(SyncWorkSpaceAction.java:271)
at org.apache.struts.action.RequestProcessor.processActionPerform(Unknown Source)
at org.apache.struts.action.RequestProcessor.process(Unknown Source)
at org.apache.struts.action.ActionServlet.process(Unknown Source)
at org.apache.struts.action.ActionServlet.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:575)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1230)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
at com.ibm.ws.console.core.servlet.WSCUrlFilter.setUpCommandAssistance(WSCUrlFilter.java:955)
at com.ibm.ws.console.core.servlet.WSCUrlFilter.continueStoringTaskState(WSCUrlFilter.java:504)
at com.ibm.ws.console.core.servlet.WSCUrlFilter.doFilter(WSCUrlFilter.java:325)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:960)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1064)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3878)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:981)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:461)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:528)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:314)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1864)
Caused by: java.lang.ArrayStoreException
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:665)
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:472)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:298)
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:234)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:81)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:64)
at com.ibm.oti.reflect.AnnotationParser.parseAnnotations(AnnotationParser.java:63)
at java.lang.Class.getDeclaredAnnotations(Class.java:1879)
at java.lang.Class.getAnnotations(Class.java:1836)
at java.lang.Class.getAnnotation(Class.java:1816)
at com.ibm.jtc.jax.xml.bind.v2.model.annotation.RuntimeInlineAnnotationReader.getClassAnnotation(RuntimeInlineAnnotationReader.java:106)
at com.ibm.jtc.jax.xml.bind.v2.model.annotation.RuntimeInlineAnnotationReader.getClassAnnotation(RuntimeInlineAnnotationReader.java:57)
at com.ibm.jtc.jax.xml.bind.v2.model.impl.ModelBuilder.getTypeInfo(ModelBuilder.java:329)
at com.ibm.jtc.jax.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:483)
at com.ibm.jtc.jax.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:319)
at com.ibm.jtc.jax.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1178)
at com.ibm.jtc.jax.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:194)
at com.ibm.jtc.jax.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:111)
at com.ibm.jtc.jax.xml.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:109)
at com.ibm.jtc.jax.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:161)
at com.ibm.jtc.jax.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:154)
at java.security.AccessController.doPrivileged(AccessController.java:327)
at com.ibm.jtc.jax.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:153)
at com.ibm.jtc.jax.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:94)
at com.ibm.jtc.jax.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:258)
at com.ibm.jtc.jax.tools.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:248)
at com.ibm.jtc.jax.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:123)
at com.ibm.jtc.jax.tools.ws.util.WSToolsObjectFactoryImpl.wsgen(WSToolsObjectFactoryImpl.java:61)
at com.ibm.jtc.jax.tools.ws.spi.WSToolsObjectFactory.wsgen(WSToolsObjectFactory.java:107)
at com.ibm.ws.websvcs.wsdl.WASWSDLGenerator.wsgen(WASWSDLGenerator.java:610)
at com.ibm.ws.websvcs.wsdl.WASWSDLGenerator.generateWsdl(WASWSDLGenerator.java:245)
... 62 more
But when I remove the provided scope , I am able to deploy without error. But we not suppose to use the validation api jar due to the requirement.
Can anyone help me what can be done to make this work with the scope as provided , I tried to use higher version of this jar but that did'nt help.
Temporarily I disabled the com.ibm.ws.beanvalidation but that is not the correct way.
Hi Scott,
Tried to generate wsdl using the wsgen where I use:
%Java_Home% as \IBM\WebSphere\AppServer\java. But no issue during the build and it geneates without any issue.
%Java_Home%\bin\wsgen -d target\classes -cp target\classes;%Nexus_Home%\org\springframework\spring-web\3.0.4.RELEASE\spring-web-3.0.4.RELEASE.jar;%Nexus_Home%\org\springframework\spring-beans\3.0.4.RELEASE\spring-beans-3.0.4.RELEASE.jar;%Nexus_Home%\com\hex\cobam\rds\cobam-rds-services\2.14.0-SNAPSHOT\cobam-rds-services-2.14.0-SNAPSHOT.jar;%Nexus_Home%\com\hex\cobam\core\cobam-core-domain\1.0.64\cobam-core-domain-1.0.64.jar;%Nexus_Home%\com\hex\cobam\rds\cobam-rds-domain\2.4.0-SNAPSHOT\cobam-rds-domain-2.4.0-SNAPSHOT.jar;%Nexus_Home%\com\hex\cobam\core\cobam-core-exception\1.0.20\cobam-core-exception-1.0.20.jar;%Nexus_Home%\joda-time\joda-time\2.9.4\joda-time-2.9.4.jar;%Java_Home%\jre\..\lib\tools.jar -wsdl -r target\classes com.hex.cobam.rds.ws.endpoint.impl.EntitySearchServiceEndpoint
The endpoint internally calls this class which uses validation api:
import javax.validation.ConstraintViolation;
import javax.xml.ws.WebFault;
#WebFault(faultBean = "com.hex.bam.core.exception.BusinessError", name = "searchRequestValidationException", targetNamespace = RDS_SERVICE_NAMESPACE)
public class SearchRequestValidationException extends BamBusinessException {
public SearchRequestValidationException(Set<ConstraintViolation<Criteria>> constraintViolations) {
super(constraintViolations);
}
Adding some more details to it:
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
public abstract class BamBusinessException extends Exception {
private static final long serialVersionUID = 1L;
protected <C> BamBusinessException(Set<ConstraintViolation<C>> constraintViolations) {
error = ErrorFactory.buildBusinessError(this, constraintViolations);
}
}
public class ErrorFactory {
public static <T extends BamBusinessException, C> BusinessError buildBusinessError(
T exception, Set<ConstraintViolation<C>> constraintViolations) {
BusinessError error = buildBusinessError(exception);
List<BasicConstraintViolation> violations = new ArrayList<BasicConstraintViolation>();
if (constraintViolations != null) {
for (ConstraintViolation<C> violation : constraintViolations) {
violations.add(parse(violation));
}
}
error.setConstraintViolationList(violations);
return error;
}
}
import static com.hex.bam.core.dto.NamespaceConstants.CORE_DTO_NAMESPACE;
import javax.xml.bind.annotation.XmlType;
#XmlType(namespace = CORE_DTO_NAMESPACE)
public class BasicConstraintViolation {
private String propertyPath;
private String resourceKey;
public void setPropertyPath(String propertyPath) {
this.propertyPath = propertyPath;
}
public void setResourceKey(String resourceKey) {
this.resourceKey = resourceKey;
}
public String getResourceKey() {
return resourceKey;
}
public String getPropertyPath() {
return propertyPath;
}
#Override
public String toString() {
return "{" + getPropertyPath() + ":::" + getResourceKey() + "}";
}
import javax.jws.HandlerChain;
import javax.xml.bind.annotation.XmlSeeAlso;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
#HandlerChain(file = "../../../../../../../handler-chain.xml")
#javax.jws.WebService(endpointInterface = ENDPOINT_INTERFACE, targetNamespace = RDS_SERVICE_NAMESPACE, serviceName = SERVICE_NAME, portName = PORT_NAME)
#XmlSeeAlso({ com.hex.bam.rds.domain.Organisation.class, com.hex.bam.rds.domain.Individual.class })
public class EntitySearchServiceEndpoint extends SpringBeanAutowiringSupport implements EntitySearchService {
#Autowired
private SearchService searchService;
#Autowired
private AuthenticationService authenticationService;
#Autowired
private ModelSupportService defaultModelSupportService;
#Autowired
private RegulatoryClassificationService regulatoryClassificationService;
#Override
public IndividualSearchResults findIndividuals(IndividualSearchCriteria individualSearchCriteria,
ClientIdentification clientIdentification) throws CobamSystemException, SearchRequestValidationException {
try {
authenticationService.authenticateOnBehalfOfUser(clientIdentification);
assertParameterSuppliedThrowsSearchRequestValidationException(individualSearchCriteria);
defaultModelSupportService.initialiseReferenceDatum(individualSearchCriteria, TreeWalker.MAX_DEPTH);
return searchService.findIndividuals(individualSearchCriteria);
} catch (RuntimeException runtimeException) {
throw ErrorFactory.buildAndLogCobamSystemException(runtimeException);
}
}
}
#WebService(name = "EntitySearchService", targetNamespace = RDS_SERVICE_NAMESPACE)
#SOAPBinding(parameterStyle = ParameterStyle.BARE)
#XmlSeeAlso({ Individual.class, Organisation.class })
public interface EntitySearchService {
#WebMethod(operationName = "findOrganisations", action = RDS_SERVICE_NAMESPACE + "findOrganisations")
#WebResult(name = "organisationSearchResults", targetNamespace = ERDS_SERVICE_NAMESPACE)
OrganisationSearchResults findOrganisations(
#WebParam(name = "organisationSearchCriteria") OrganisationSearchCriteria organisationSearchCriteria,
#WebParam(name = "findOrganisationsClientIdentification", header = true) ClientIdentification clientIdentification)
throws BamSystemException, SearchRequestValidationException;
}
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlType;
import com.hex.bam.core.dto.BasicConstraintViolation;
#XmlType(name = "businessError", namespace = EXCEPTION_NAMESPACE)
public class BusinessError extends Error {
private final List<BasicConstraintViolation> constraintViolationList;
public BusinessError(Date occuredAt, String resourceKey, String guid,
List<BasicConstraintViolation> constraintViolationList) {
super(occuredAt, resourceKey, guid);
this.constraintViolationList = constraintViolationList;
}
public List<BasicConstraintViolation> getConstraintViolationList() {
return constraintViolationList;
}
#Override
public String toString() {
String violations = constraintViolationList != null ? constraintViolationList.toString() : " none ";
return getGuid() + " - Business Error - " + getResourceKey() + " [" + violations + "]";
}
}
`public class GenericUdafMemberLevel implements GenericUDAFResolver2 {
private static final Log LOG = LogFactory
.getLog(GenericUdafMemberLevel.class.getName());
#Override
public GenericUDAFEvaluator getEvaluator(GenericUDAFParameterInfo paramInfo)
throws SemanticException {
return new GenericUdafMeberLevelEvaluator();
}
#Override
//参数校验
public GenericUDAFEvaluator getEvaluator(TypeInfo[] parameters)
throws SemanticException {
if (parameters.length != 2) {//参数大小
throw new UDFArgumentTypeException(parameters.length - 1,
"Exactly two arguments are expected.");
}
//参数必须是原型,即不能是
if (parameters[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
throw new UDFArgumentTypeException(0,
"Only primitive type arguments are accepted but "
+ parameters[0].getTypeName() + " is passed.");
}
if (parameters[1].getCategory() != ObjectInspector.Category.PRIMITIVE) {
throw new UDFArgumentTypeException(1,
"Only primitive type arguments are accepted but "
+ parameters[1].getTypeName() + " is passed.");
}
return new GenericUdafMeberLevelEvaluator();
}
public static class GenericUdafMeberLevelEvaluator extends GenericUDAFEvaluator {
private PrimitiveObjectInspector inputOI;
private PrimitiveObjectInspector inputOI2;
private DoubleWritable result;
#Override
public ObjectInspector init(Mode m, ObjectInspector[] parameters)
throws HiveException {
super.init(m, parameters);
if (m == Mode.PARTIAL1 || m == Mode.COMPLETE){
inputOI = (PrimitiveObjectInspector) parameters[0];
inputOI2 = (PrimitiveObjectInspector) parameters[1];
result = new DoubleWritable(0);
}
return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
}
/** class for storing count value. */
static class SumAgg implements AggregationBuffer {
boolean empty;
double value;
}
#Override
//创建新的聚合计算的需要的内存,用来存储mapper,combiner,reducer运算过程中的相加总和。
//使用buffer对象前,先进行内存的清空——reset
public AggregationBuffer getNewAggregationBuffer() throws HiveException {
SumAgg buffer = new SumAgg();
reset(buffer);
return buffer;
}
#Override
//重置为0
//mapreduce支持mapper和reducer的重用,所以为了兼容,也需要做内存的重用。
public void reset(AggregationBuffer agg) throws HiveException {
((SumAgg) agg).value = 0.0;
((SumAgg) agg).empty = true;
}
private boolean warned = false;
//迭代
//map阶段调用,只要把保存当前和的对象agg,再加上输入的参数,就可以了。
#Override
public void iterate(AggregationBuffer agg, Object[] parameters)
throws HiveException {
// parameters == null means the input table/split is empty
if (parameters == null) {
return;
}
try {
double flag = PrimitiveObjectInspectorUtils.getDouble(parameters[1], inputOI2);
if(flag > 1.0) //参数条件
merge(agg, parameters[0]); //这里将Map之后的操作,放入combiner进行合并
} catch (NumberFormatException e) {
if (!warned) {
warned = true;
LOG.warn(getClass().getSimpleName() + " "
+ StringUtils.stringifyException(e));
}
}
}
#Override
//combiner合并map返回的结果,还有reducer合并mapper或combiner返回的结果。
public void merge(AggregationBuffer agg, Object partial)
throws HiveException {
if (partial != null) {
//通过ObejctInspector取每一个字段的数据
double p = PrimitiveObjectInspectorUtils.getDouble(partial, inputOI);
((SumAgg) agg).value += p;
}
}
#Override
//reducer返回结果,或者是只有mapper,没有reducer时,在mapper端返回结果。
public Object terminatePartial(AggregationBuffer agg)
throws HiveException {
return terminate(agg);
}
#Override
public Object terminate(AggregationBuffer agg) throws HiveException {
result.set(((SumAgg) agg).value);
return result;
}
}
}`
I have used some chinese to comment the code for understanding the theory.
Actually, the idea of the UDAF is like follow:
select test_sum(col1,col2) from tbl ;
if col2 satisfy some condition, then sum col1's value.
Most of the code are copied from the offical avg() udaf function.
I met a weried Exception:
java.lang.RuntimeException: Hive Runtime Error while closing operators
at org.apache.hadoop.hive.ql.exec.ExecMapper.close(ExecMapper.java:226)
at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:57)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:436)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:372)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1136)
at org.apache.hadoop.mapred.Child.main(Child.java:249)
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.ClassCastException: org.apache.hadoop.io.DoubleWritable cannot be cast to org.apache.hadoop.io.LongWritable
at org.apache.hadoop.hive.ql.exec.GroupByOperator.closeOp(GroupByOperator.java:1132)
at org.apache.hadoop.hive.ql.exec.Operator.close(Operator.java:558)
at org.apache.hadoop.hive.ql.exec.Operator.close(Operator.java:567)
at org.apache.hadoop.hive.ql.exec.Operator.close(Operator.java:567)
at org.apache.hadoop.hive.ql.exec.Operator.close(Operator.java:567)
at org.apache.hadoop.hive.ql.exec.ExecMapper.close(ExecMapper.java:193)
... 8 more
Caused by: java.lang.ClassCastException: org.apache.hadoop.io.DoubleWritable cannot be cast to org.apache.hadoop.io.LongWritable
at org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableLongObjectInspector.get(WritableLongObjectInspector.java:35)
at org.apache.hadoop.hive.serde2.lazybinary.LazyBinarySerDe.serialize(LazyBinarySerDe.java:323)
at org.apache.hadoop.hive.serde2.lazybinary.LazyBinarySerDe.serializeStruct(LazyBinarySerDe.java:255)
at org.apache.hadoop.hive.serde2.lazybinary.LazyBinarySerDe.serialize(LazyBinarySerDe.java:202)
at org.apache.hadoop.hive.ql.exec.ReduceSinkOperator.processOp(ReduceSinkOperator.java:236)
at org.apache.hadoop.hive.ql.exec.Operator.process(Operator.java:474)
at org.apache.hadoop.hive.ql.exec.Operator.forward(Operator.java:800)
at org.apache.hadoop.hive.ql.exec.GroupByOperator.forward(GroupByOperator.java:1061)
at org.apache.hadoop.hive.ql.exec.GroupByOperator.closeOp(GroupByOperator.java:1113)
... 13 more
Am I have something wrong with my UDAF??
please kindly point it out.
Thanks a lllllllot .
Replace PrimitiveObjectInspectorFactory.writableLongObjectInspector in init method with PrimitiveObjectInspectorFactory.writableDoubleObjectInspector.
I have a slight problem that I don't know how to solve. Could you help me please?
When I am trying to persist entity I get next exception:
12:47:39,398 ERROR [org.black.dmitriy.entityHome.ScheduleHome] (http--127.0.0.1-8080-1) javax.persistence.EntityExistsException: a different object with the same identifier value was already associated with the session: [org.black.dmitriy.entity.Schedule#1]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1333) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1295) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:859) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_04]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_04]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_04]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_04]
at org.jboss.seam.persistence.EntityManagerInvocationHandler.invoke(EntityManagerInvocationHandler.java:46) [jboss-seam.jar:2.3.0.Final]
at $Proxy81.persist(Unknown Source) at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:84) [jboss-seam.jar:2.3.0.Final]
at org.black.dmitriy.entityHome.ConversationHome.tryPersist(ConversationHome.java:147) [ejb.jar:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_04]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_04]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_04]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_04]
at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:65) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.util.Work.workInTransaction(Work.java:61) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:186) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:104) [jboss-seam.jar:2.3.0.Final]
at org.black.dmitriy.entityHome.ScheduleHome_$$_javassist_seam_8.tryPersist(ScheduleHome_$$_javassist_seam_8.java) [ejb.jar:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_04]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_04]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_04]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_04]
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335) [jboss-el-1.0_02.CR6.jar:1.0_02.CR6]
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348) [jboss-el-1.0_02.CR6.jar:1.0_02.CR6]
at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58) [jboss-el-1.0_02.CR6.jar:1.0_02.CR6]
at org.jboss.el.parser.AstValue.invoke(AstValue.java:96) [jboss-el-1.0_02.CR6.jar:1.0_02.CR6]
at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) [jboss-el-1.0_02.CR6.jar:1.0_02.CR6]
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.component.UICommand.broadcast(UICommand.java:315) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) [jboss-seam.jar:2.3.0.Final]
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158) [jboss-seam.jar:2.3.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:397) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_04]
I use seam 2.3, hibernate. I have one insert statement in my import.sql file:
INSERT INTO Schedules (id, name, dayCount, lessonCount, firstTermSize, secondTermSize, subgroupSize) VALUES(1, '2012/2013', 5, 8, 9, 9, 18)
which inserts one enity into table Schedules.
Then I create new Schedule entity throw web page using EntityHome
#Name("scheduleHome")
#Scope(ScopeType.CONVERSATION)
public class ScheduleHome extends ConversationHome<Schedule> {
private static final long serialVersionUID = 1L;
public ScheduleHome() {
}
#Override
protected boolean isUnique() {
Schedule schedule = getInstance();
Schedule foundSchedule = ScheduleDAO.instance().getByName(schedule.getName());
if ((foundSchedule != null) && (!foundSchedule.equals(schedule))) {
showExistsErrorMessage(getInstance().getName());
return false;
}
return true;
}
#Override
protected Schedule createInstance() {
return new Schedule();
}
#Override
public String getEditOutcome() {
return "scheduleEdit";
}
#Override
protected void prepareEntityForSaving() {
}
}
and the superclass
public abstract class ConversationHome<T> extends EntityHome<T> {
private static final long serialVersionUID = 1L;
private String parentView;
public boolean isParentViewExists() {
return parentView != null && parentView.length() > 0;
}
public void setParentView(String parentView) {
this.parentView = parentView;
}
public String getParentView() {
return parentView;
}
public abstract String getEditOutcome();
protected abstract void prepareEntityForSaving();
protected abstract boolean isUnique();
#Override
#Create
public void create() {
create(false);
}
protected void create(boolean createNestedConversation) {
Conversation conversation = Conversation.instance();
if (!createNestedConversation && conversation.isLongRunning()) {
getLog().debug("conversation already started, nested will not create(isLongRunning = #0, isNested = #1)", conversation.isLongRunning(), conversation.isNested());
} else {
conversation.begin(false, conversation.isLongRunning());
conversation.changeFlushMode(FlushModeType.MANUAL);
getLog().debug("create(isLongRunning = #0, isNested = #1, id = #2)", conversation.isLongRunning(), conversation.isNested(), conversation.getId());
}
super.create();
}
private boolean init(Long id) {
FacesContext context = FacesContext.getCurrentInstance();
setParentView(Pages.getViewId(context));
if (id != null) {
setId(id);
try {
getInstance();
getLog().debug("instance initialized #0", getInstance());
} catch (EntityNotFoundException e) {
getLog().error(e);
return false;
}
}
return true;
}
public String startEdit(Long id) {
getLog().debug("start editing #0", id);
if (init(id)) {
return getEditOutcome();
} else {
return cancel();
}
}
public String cancel() {
if (isManaged()) {
getEntityManager().refresh(getInstance());
}
return returnToParent();
}
#End
protected String returnToParent() {
if (isParentViewExists()) {
Conversation conversation = Conversation.instance();
getLog().debug("end conversation(id = #0, isLongRunning = #1, isNested = #2)",
conversation.getId(), conversation.isLongRunning(), conversation.isNested());
conversation.end(true);
return getParentView();
} else {
clearInstance();
return null;
}
}
public String tryPersist() {
if (isUnique()) {
try {
prepareEntityForSaving();
String outcome = persist();
if (!"failed".equals(outcome)) {
return returnToParent();
}
} catch (Exception e) {
getLog().error(getInstance(), e);
showSaveErrorMessage(e);
}
}
return "failed";
}
}
and when i try to persist it i get this exception. and message on web page
Save error with message: a different object with the same identifier value was already associated with the session: [org.black.dmitriy.entity.Schedule#1]
It seams that hibernate set id property to 1, but I already have entity with id = 1, because I manually created it throw import.sql.
Here is my Schedule entity :
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
#Entity
#Table(name = "Schedules")
public class Schedule {
#Id
#GeneratedValue
#Column(name = "id", nullable = false)
private Long id;
#NotNull
#Column(name = "name", nullable = false, length = 40)
private String name;
#Column(name = "dayCount")
private int dayCount = 5;
#Column(name = "lessonCount")
private int lessonCount = 8;
#Column(name = "firstTermSize")
private int firstTermSize = 9;
#Column(name = "secondTermSize")
private int secondTermSize = 9;
#Column(name = "subgroupSize")
private int subgroupSize = 18;
#OneToMany(mappedBy = "schedule", cascade = CascadeType.ALL, targetEntity = Faculty.class)
private List<Faculty> faculties = new ArrayList<>();
#OneToMany(mappedBy = "schedule", cascade = CascadeType.ALL, targetEntity = Building.class)
private List<Building> buildings = new ArrayList<>();
public Schedule() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getDayCount() {
return dayCount;
}
public void setDayCount(int dayCount) {
this.dayCount = dayCount;
}
public int getLessonCount() {
return lessonCount;
}
public void setLessonCount(int lessonCount) {
this.lessonCount = lessonCount;
}
public int getFirstTermSize() {
return firstTermSize;
}
public void setFirstTermSize(int firstTermSize) {
this.firstTermSize = firstTermSize;
}
public int getSecondTermSize() {
return secondTermSize;
}
public void setSecondTermSize(int secondTermSize) {
this.secondTermSize = secondTermSize;
}
public int getSubgroupSize() {
return subgroupSize;
}
public void setSubgroupSize(int subgroupSize) {
this.subgroupSize = subgroupSize;
}
public List<Faculty> getFaculties() {
return faculties;
}
public void setFaculties(List<Faculty> faculties) {
this.faculties = faculties;
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Schedule)) {
return false;
}
Schedule other = (Schedule) obj;
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
return true;
}
#Override
public String toString() {
return this.name;
}
}
As you can see there is #GeneratedValue annotation on id property, so I think that hibernate should generate id himself and hibernate should know that there is entity in database with id = 1, and set id in new entity = 2. But Hibernate sets id in new entity to 1.
Could you halp me please?
The problem was how hibernate generates your id's, it starts from 1. When it assigns 1 to an object before saving it into database, it sees a row with same id already exists in the database and causes the exception. The simple and natural solution of this problem is simply to restrict hibernate, so that it can not assign 1 as an id to any object of the concerning class (in your case).
Solution for mySql:
If you are using mySql, you can create table manually and set the auto increment like:
CREATE TABLE IF NOT EXISTS `testTable` (
`id` number(11) NOT NULL AUTO_INCREMENT,
...,
...,
...,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2; //assigning id by hibernate, will start from 2.
And in your domain class you can have id annotated like bellow:
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "ID")
public long getId() {
....
}
GenerationType.AUTO by default uses auto increment in mySql. and after setting AUTO_INCREMENT=2 hibernate will start assigning id's from 2 (hence 1 is skipped).
Solution for Oracle:
The same thing for oracle can be done if you restrict hibernate use a "sequence" and you set the initial point of the sequence as your wish. You can create a sequence to be start from 2 and increment by 1 like bellow:
create sequence idSequence
start with 2
increment by 1
maxvalue 9999999999999;
And you can specify your sequence to be used to generate id's of your domain class's object like bellow:
#Id
#SequenceGenerator(name = "idGeneratorSeq", sequenceName = "idSequence")
#GeneratedValue(strategy = GenerationType.AUTO, generator = "idGeneratorSeq")
#Column(name = "ID")
public long getId() {
....
}
And your problem is sovled.
Do the following steps before calling persist() method.
First detach your current instance
getEntityManager().detach(getInstance());
Now set its Id to null
getInstance().setId(null);
Now persist
String outcome = persist();