java,hibernate,spring,jpa,exception-handlingRelated issues-Collection of common programming errors
A Question Asker
java
I am trying to make the following work:import java.io.Serializable; public abstract class Thing implements Iterable<? extends Serializable> {} But I compile and get the following error:Thing.java:2: unexpected type found : ? extends java.io.Serializable required: class or interface without bounds public abstract class Thing extends Iterable<? extends Serializable> {}I’m not sure why there is ambiguity here? Shouldn’t the compiler know what I am intending? I’d love to be able to get
YS Bhai
java android ubuntu jvm heap
I want to increase my Heap size. How can I use JAVA_OPTS for doing so.I am getting the following error may be this is because of low heap sizeUNEXPECTED TOP-LEVEL ERROR: java.lang.OutOfMemoryError: Java heap spaceat java.util.Arrays.copyOfRange(Arrays.java:3209)at java.lang.String.<init>(String.java:215)at java.lang.StringBuilder.toString(StringBuilder.java:430)at com.android.dx.rop.type.Prototype.withFirstParameter(Prototype.java:370)at com.android.dx.rop.code.Rops.ropFor(Rops.java:1210)a
Dmitry Berdnikov
java oop
I’m new to Java and to OOP, so some things below may sound silly, but…I understand a situation when i have two classes (two different types) and one does whatever it wants with the instance of the other one, likeclass A { … }class B { …public A someMethod() { return new A;}… }At the point when B’s method is declaring some code to work with A, the A type is pretty defined and complete and thus one thing can use/make something with another. That all is pretty logical for me at this point.B
vivek rai
java hibernate java-ee jboss jboss7.x
Hi every one i have some problem with Jboss-7-as.1.1 when i deploy i am getting ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service error.10:44:30,343 INFO [org.jboss.as.connector] (MSC service thread 1-1) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.7.Final) 10:44:30,765 INFO [org.jboss.as.naming] (MSC service thread 1-2) JBAS011802: Starting Naming Service 10:44:31,750 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1
Andrew Thompson
java swing arraylist nullpointerexception
I am getting nullpointer exception on this code from the paintcomponent method public A1Panel() {final ArrayList<MySnowFlake> myShapes = new ArrayList<MySnowFlake>(); //Stage 1: Replace this linepopup = new JPopupMenu(); //create the popup menumakePopupMenu();addMouseListener( new MouseAdapter() {public void mousePressed(MouseEvent e) {maybeShowPopup(e);}public void mouseReleased(MouseEvent e) {maybeShowPopup(e);}private void maybeShowPopup(MouseEvent e) {if (e.isPop
Ismail Marmoush
java redirect timeout urlconnection
From the output I understood that the website homepage does refresh and redirects the request to other page that happens ok on a browser but it doesn’t on code. so how do I move forward along with that redirection ? try {URL url = StringUtils.stringToURL(link);URLConnection dbGatewayURL = url.openConnection();dbGatewayURL.setConnectTimeout(timeout);BufferedReader in = new BufferedReader(new InputStreamReader(dbGatewayURL.getInputStream()));StringBuffer responseData = new StringBuffer();String li
matt b
java hibernate orm jpa jdo
I’m familiar with ORM as a concept, and I’ve even used nHibernate several years ago for a .NET project; however, I haven’t kept up with the topic of ORM in Java and haven’t had a chance to use any of these tools.But, now I may have the chance to begin to use some ORM tools for one of our applications, in an attempt to move away from a series of legacy web services.I’m having a hard time telling the difference betweeen the JPA spec, what you get with the Hibernate library itself, and what JDO has
Cricket
java mysql eclipse tomcat connection-pooling
I’m using tomcat and mysql (the ide is eclipse). I’m using the connection pool.In the context.xml, I have:<Resource name=”jdbc/mydb” auth=”Container” type=”javax.sql.DataSource”maxActive=”100″ maxIdle=”30″ maxWait=”10000″username=”root” password=”root” driverClassName=”com.mysql.jdbc.Driver”url=”jdbc:mysql://localhost:3306/mydb” factory=”org.apache.tomcat.jdbc.pool.DataSourceFactory” />At the beginning I’ve been using the mysql in easyphp (the user root had no pwd). All worked. Then I’ve
Marcin
java reflection junit easymock
I’m using EasyMock to create mock that is one of private parameters (without setter) in tested class. I tried using reflection – but it does not work correctly. public class TestedClassTest{@Testpublic void test(){TestedClass instance = new TestedClass();MockedClass mocked = EasyMock.createMock(MockedClass.class);Data data = new Data();//Void setterDataType dataType = (myDataType.DataType) EasyMock.anyObject();mocked.setDataType(dataType);EasyMock.expectLastCall();//expectEasyMock.expect(mocked.
Arthur Ulfeldt
java clojure
ContextThis is purely for education purposes. I want to write a primitive database. Focus is NOT on performance; but just the principles behind databases. I have material already on locking / mutexes / transactions. What I know nothing about is writing to disk / guaranteeing persistence in unexpected hardware (say power) failures.In order to have proper recovery / persistence, I need certain guarantees when writing files to disk.Question:For the above purposes, what types of file primitives (gua
vivek rai
java hibernate java-ee jboss jboss7.x
Hi every one i have some problem with Jboss-7-as.1.1 when i deploy i am getting ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service error.10:44:30,343 INFO [org.jboss.as.connector] (MSC service thread 1-1) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.7.Final) 10:44:30,765 INFO [org.jboss.as.naming] (MSC service thread 1-2) JBAS011802: Starting Naming Service 10:44:31,750 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1
matt b
java hibernate orm jpa jdo
I’m familiar with ORM as a concept, and I’ve even used nHibernate several years ago for a .NET project; however, I haven’t kept up with the topic of ORM in Java and haven’t had a chance to use any of these tools.But, now I may have the chance to begin to use some ORM tools for one of our applications, in an attempt to move away from a series of legacy web services.I’m having a hard time telling the difference betweeen the JPA spec, what you get with the Hibernate library itself, and what JDO has
user1714514
hibernate
I have a class mapped with DB with 8 column but in hql i am creating 9th column in select statement , with case when statement. it is giving unexpected toekn, seems to be syntax error. But I am not able to figure out the exact syntax error. Exception I got org.jboss.resteasy.spi.UnhandledException: javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 353 [select un.id, un.timestamp, un.recipientUser, un.se
digiarnie
java hibernate jpa
Let’s say I have the following code:public void doSomething() {// begin transaction// do stuff 1…// update a row which must be committed now…// do stuff 2…// commit transaction }I’ve kept the large amount of work on the database in the one method to simplify the pseudo code. However, basically I have a series of database work that I won’t want to commit until the end. In the middle of the transaction above, I need to commit something to a row without committing the rest of the transactio
Bozho
java hibernate playframework
I am trying to build query in Play framework, I haveselect * from Candidate c where (:schools member of c.schools) After I bind :school with List with one element it returns result, but if I bind List with multiple elements nothing happens.Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: {vector} [select c from models.Candidate c where (:schools0_, :schools1_ member of c.schools) group by c.id order by RAND()]Actually I need something like select * from candidate wher
yglodt
java hibernate postgresql hql
Here is my Entity which I want to query with Hibernate 4.3.4:@Entity @DynamicInsert @DynamicUpdate public class Device extends OrmEntity implements Serializable {@Column(name = “is_on”) // was necessary to get Hibernate to create the table at allprivate boolean on;… }This is the HQL I want to execute (btw the database is PostgreSQL):Query query = session.createQuery(“from Device where … and on = :a”); query.setBoolean(“a”, true);This gives me org.hibernate.hql.internal.ast.QuerySyntaxExcepti
Aaron Digulla
java sql oracle hibernate hql
I am using oracle 10g and hibernate 3.3.2. I have used regular expression in sql before, now for the first time I am using it in HQL.Query query = getSession().createQuery(“From Company company where company.id!=:companyId and regexp_like(upper(rtrim(ltrim(company.num))), ‘^0*514619915$’ )”);This is my hql, when i run it without regex_like function it runs as expected. But I am not able to execute it with regex_like expression. It says..nested exception is org.hibernate.hql.ast.QuerySyntaxExce
casperOne
hibernate postgresql insert database-partitioning
is there a solution for batch insert via hibernate in partitioned postgresql table? currently i’m getting an error like this…57286 [pool-1-thread-18] ERROR org.hibernate.jdbc.AbstractBatcher – Exception executing batch: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61) at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutc
Maciej Ziarko
hibernate grails groovy spring-security hql
I have the following:def userInstance=User.findAll(“from User u where u.merchant is not null and u.merchant.id = ? and u.authorities.authority.contains(‘ROLE_MERCHANT’)”, merchantId)And get the following error:org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: ( near line 1, column 121 [from com.testing.tests.User u where u.merchant is not null and u.merchant.id = ? and u.authorities.authority.contains(‘ROLE_MERCHANT’)]at $Proxy20.createQuery(Unknown Source)at testing.admin.UserSer
Alex
java hibernate utf-8 character-encoding jersey
I am writing a REST API. I fetch data from a database and store it in a String. Then I send it back to the browser like this://fetch data from database String s = …// Prepare it for browser byte[] data = s.getBytes(“UTF-8”);// Send it to browser now out.write(data); // out is an OutputStream received from Jersey through the MessageBodyWriter interfaceThe data comes from a postgresql database with UTF8 encoding. The data is stored in a character varying(5000).When the browser (Chrome) displays
Steve
spring jpa junit4
Our project has just decided to migrate from Spring 2.5.5 to Spring 3.0.4. In my original code, I had unit tests that looked like the following:public class RequisitionDaoTest extends AbstractJpaTests {public static String FAIL_MSG_UNEXPECTED_ERROR = “FAIL: Unexpected Error”;@PersistenceContextprivate EntityManager em;@PersistenceUnitprivate EntityManagerFactory emf;@Testpublic void testSomething (){…} }This worked just fine with Spring 2.5.5. Now with Spring 3.0.4, the AbstractJpaTests class
micfra
spring spring-el
Given a class containing an enum:public class MyClass {public enum NestedEnum { value1(1),value2(2);private int code;private NestedEnum(int code) {this.code = code;}public int getCode() {return code;}} }how do I reference NestedEnum? This:#{T(MyClass.NestedEnum).value1.getCode()}results in the exception:org.springframework.expression.spel.SpelEvaluationException: EL1005E:(pos 0): Type cannot be found ‘namespace.MyClass.NestedEnum’This:#{T(T(MyClass).NestedEnum).value1.getCode()}results i
Tom
java spring
I’m using a local override to specify a property and wanted to confirm that this just applies to properties that are specified in the applicationContext. Basically I want to make sure that this doesn’t have any unexpected consequences…<context:property-placeholderproperties-ref=”defaultProperties”location=”classpath:my.properties”ignore-resource-not-found=”true”ignoreunresolvable=”true”local-override=”true”/><util:properties id=”defaultProperties”><prop key=”some.property”>${
Soner Gönül
spring
I am getting the below error when I try to configure a spring-hibernate application:org.springframework.beans.factory.BeanDefinitionStoreException:Unexpected exception parsing XML document from ServletContext resource[/WEB-INF/spring-servlet.xml]; nested exception isjava.lang.NoSuchMethodError:org.springframework.beans.MutablePropertyValues.add(Ljava/lang/String;Ljava/lang/Object;)Lorg/springframework/beans/MutablePropertyValues;I have org.springframework.beans-3.0.0.M3.jar in the build path.Ple
Derek Troy-West
spring aspectj
Is it possible to have two AfterThrows pieces of advice be applied to the same pointcut restricted by specific Exception type where one exception is a superclass of the other with, in the case of the subclass being captured, only one advice being executed?I want to translate runtime exceptions (both custom and standard java ones) being chucked out of a service layer, where I do some specific translation in certain cases and then have a catch-all type piece of advice to translate anything truly u
mmelear
spring mongodb grails oauth2client
I am working on an app that uses a mongodb, is built in grails, and is using oauth2 as an authentication service. I have the services and controller built out (I think) and am trying to run my server to manually test connectivity with google. I am running into an “Error creating bean with name transactionManagerPostProcessor…” that I can’t solve. I know I need to either install a plug-in that takes care of the “transactions” for me, or create a bean in resources.groovy. I have done a lot of re
zhizhu2012
spring properties
<context:property-placeholder location=”WEB-INF/classes/config.config”/> config.config: path=com<import resource=”../../conf/${path}/test.xml”/>error:org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from file [test.service.xml]; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder ‘path’at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader
Tony
java spring hibernate nullpointerexception
I want to insert some data into my DB. But I catch “ERROR: org.springframework.scheduling.support.TaskUtils$LoggingErrorHandler – Unexpected error occurred in scheduled task. java.lang.NullPointerException”I don’t know what to do.public class HeadHunterImport {@Autowiredprivate static HeadHunterService headHunterService;@Scheduled(fixedRate = 600000)public void AsyncRemovalOldData() {headHunterService.addHeadHunter(“Moscow”, 100, 100) ; }If I’ll call it in controller it will work fine. What’s w
sonoerin
spring hibernate querydsl
Currently Using:Hibernate 4.0.1.Final Spring-data-jpa: 1.0.3.RELEASE QueryDSL: 2.3.0 MySQL 5.xI have an interesting problem that I have not found the answer, or clue for yet. I have two tables that did not have foreign key or other relationship. But to try and solve this issue I added one. I want my User entity to hold it’s UserRole. This pattern is repeated throughout the database, but this is the easiest to describe. Here are my tables:UseruserId bigint(20) PK password varc
Jigar Joshi
java hibernate spring data
Maybe someone can help, how do i fix this? I’m using hibernate, spring and gwt.com.google.gwt.user.server.rpc.UnexpectedException:Service method ‘public abstract voidcom.yeah.client.service.PictureService.saveItem(com.yeah.shared.model.Picture)’threw an unexpected exception:org.springframework.dao.DataIntegrityViolationException:could not insert:[com.yeah.shared.model.Picture]; SQL[insert into YeaH.Picture (albumID,picLocation) values (?, ?)];constraint [null]; nested exception isorg
matt b
java hibernate orm jpa jdo
I’m familiar with ORM as a concept, and I’ve even used nHibernate several years ago for a .NET project; however, I haven’t kept up with the topic of ORM in Java and haven’t had a chance to use any of these tools.But, now I may have the chance to begin to use some ORM tools for one of our applications, in an attempt to move away from a series of legacy web services.I’m having a hard time telling the difference betweeen the JPA spec, what you get with the Hibernate library itself, and what JDO has
Steve
spring jpa junit4
Our project has just decided to migrate from Spring 2.5.5 to Spring 3.0.4. In my original code, I had unit tests that looked like the following:public class RequisitionDaoTest extends AbstractJpaTests {public static String FAIL_MSG_UNEXPECTED_ERROR = “FAIL: Unexpected Error”;@PersistenceContextprivate EntityManager em;@PersistenceUnitprivate EntityManagerFactory emf;@Testpublic void testSomething (){…} }This worked just fine with Spring 2.5.5. Now with Spring 3.0.4, the AbstractJpaTests class
digiarnie
java hibernate jpa
Let’s say I have the following code:public void doSomething() {// begin transaction// do stuff 1…// update a row which must be committed now…// do stuff 2…// commit transaction }I’ve kept the large amount of work on the database in the one method to simplify the pseudo code. However, basically I have a series of database work that I won’t want to commit until the end. In the middle of the transaction above, I need to commit something to a row without committing the rest of the transactio
Sean Patrick Floyd
java mysql orm jpa jpql
I have a query builded with EntityManager:Query q = em.createQuery(“SELECT * FROM :table WHERE username = :username AND password = MD5(:password)”).setParameter(“table”, User.class.getName()).setParameter(“username”, txtLogin.getText()).setParameter(“password”, passPassword.getPassword()) ;User user = (User) q.getSingleResult();but I get an exception:Exception in thread “AWT-EventQueue-0″java.lang.IllegalArgumentException: Anexception occurred while creating aquery in EntityManager:ExceptionDesc
cmd
java-ee jpa eclipselink jpql
MySQL supports queries such as:SELECT id FROM users WHERE id IN(3,4,8,1) ORDER BY FIELD(id, 3,4,8,1);Does EclipseLink support this query (without reverting to a native query)?When I try the following:Select id from User user where user.id in :ids ORDER BY FIELD(user.id, :ids)I receive the error:Syntax error parsing the query … line 1, column 98: unexpected token [(].
williamssimonp
java-ee jpa
I am just starting out with JPA and I have what may well be a stupid question, but if it is, it means that there is something fairly fundamental about JPA! Please forgive me if this is a stupid question, but I have not been able to find the answer anywhere.I want to auto-generate UUIDs for the primary keys of my tables and I have read a lot about how to do this and read all the warnings about the ID not being available until the object is persisted and how this can affect the equals and hashCod
Vineet Reynolds
jpa
I’m facing quite a basic issue (allegedly..). This is the structure I’m refering to:I’m working with flex in the client side, Java & open JPA in the server side and microsoft SQL server persistency layer.In my app (in the client side) it is possible to decide if a client is participant advised not advised. Suppose I have ‘Joe’ as an advised client and now I’m converting Joe to ‘not advised’ (this is done from the client side by simply un-checking a check nox).In the backend, I’m removing the
Pascal Thivent
java jpa subquery jpql toplink
I hava 2 objects associate by oneToMany relationship(“One Model can have many events”).I’m trying to make a subquery in ejbql to find models for one event, like this:SELECT model FROM RegModelValue model WHERE :event IN (model.events)…. but toplink doent recognize model alias and tell me “Internal Exception: line 1:129: unexpected token: model” Any ideas ?Thanks a lot by advance !
Ross Peoples
java jpa eclipselink
I am new to Java and JPA. I am trying to connect to a database and return some results from a table, but when I run the query, I get an empty list as a result even though the table has over 100,000 rows.Here is my persistence.xml:<?xml version=”1.0″ encoding=”UTF-8″?> <persistence xmlns=”http://java.sun.com/xml/ns/persistence” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistenc
Morcalavin
java jpa jpql
I am working on some inherited code and I am not use to the entity frame work. I’m trying to figure out why a previous programmer coded things the way they did, sometimes mixing and matching different ways of querying data.Deal d = _em.find(Deal.class, dealid); List<DealOptions> dos = d.getDealOptions(); for(DealOptions o : dos) {if(o.price == “100”) {//found the 1 item i wanted} }And then sometimes i see this:Query q = _em.createQuery(“select count(o.id) from DealOptions o where o.price
skaffman
php exception-handling
When throwing a new exception is it best to simply return true if no exception needs to be thrown. Alternatively is it best to return false instead of throwing an exception. Im using php.
Inderpal Singh
python exception inheritance exception-handling custom-exceptions
I am customizing exceptions in my python code. I have inherited exception class in to other and now defining some custom errors as classes derived from my custom exception class like this:class DataCollectorError(Exception): pass class ParamNullError(DataCollectorError) : pass class ParamInvalidTypeError(DataCollectorError) : passI am raising these exceptions in my python function like:def READ_METER_DATA (regIndex, numRegisters, slaveUnit):try:if not regIndex:raise ParamNullError, “register ind
pkubik
c++ exception exception-handling
No doubt exceptions are usefull as they show programmer where he’s using functions incorrectly or something bad happens with an environment but is there a real need to catch them?Not caught exceptions are terminating the program but you can still see where the problem is. In well designed libraries every “unexpected” situation has actually workaround. For example using map::find instead of map::at, checking whether your int variable is smaller than vector::size prior to using index operator.Why
jjnguy
vb.net exception exception-handling try-catch
I am handling errors via my global.asax in this method:Dim CurrentException As Exception CurrentException = Server.GetLastError() Dim LogFilePath As String = Server.MapPath(“~/Error/” & DateTime.Now.ToString(“dd-MM-yy.HH.mm”) & “.txt”) Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter(LogFilePath) sw.WriteLine(DateTime.Now.ToString) sw.WriteLine(CurrentException.ToString()) sw.Close()In my code I currently have no other error handling. Should I still insert try, catch, finall
James McNellis
exception-handling windows-runtime hresult
If a Windows runtime type raises a COM error .NET seems to wrap this error often (or always?) just into an Exception instance. The error message includes the COM HRESULT error code. When using the new Cryptographic API with AES-CBC for example a wrong buffer length results in an Exception with the message “The supplied user buffer is not valid for the requested operation. (Exception from HRESULT: 0x800706F8)”.Well. How are we supposed to handle those exceptions? Read the HRESULT code from the ex
sonal
java exception-handling
This question already has an answer here:Does finally always execute in Java?27 answersJavas return value in try-catch-finally mechanism3 answersIf execution doesn’t cause exception then control goes to finally block. So is the return statement in try block is being ignored by JVM? . Or if exception occurs then control goes to catch block there also it ignored return statment and control go to finally block and return from finallypublic class Helper {public int showException(int a, int b){try{in
Vineet Menon
java exception interface exception-handling
I have the following interface:public interface ICalculationRule {public void calculate(EventBag eventBag); }and I would like to provide some way to indicate if calculation failed, what would be more correct?add throws Exception to method signature make calculate method boolean (true=success, false – failure)
EAGER_STUDENT
c++ exception-handling try-catch
I am trying queue implementation in c++. During that I am having this problem.void Queue::view() {int i;try{if(Qstatus==EMPTY){UnderFlowException ex = UnderFlowException(“\nQUEUE IS EMPTY”);throw ex;}}i=front;cout<<“Queue contains…\n”;while(i <= rear){cout<<queue[i]<<” “;i++;} }This gives an error as : error: expected ‘catch’ before ‘i’I think this problem is arises since I doesn’t written catch block below try block. But If want to write the catch block in main(), ( like
om-nom-nom
java swing exception-handling
I am using threading in application through Swing Worker class. It works fine, yet I have a bad feeling about showing an error message dialog in try-catch block. Can it potentially block the application? This is what it looks right now:SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {// Executed in background threadpublic Void doInBackground() {try {DoFancyStuff();} catch (Exception e) {e.printStackTrace();String msg = String.format(“Unexpected problem: %s”, e.toString
ANTLRStarter
javascript google-chrome exception-handling compiler-errors position
How can I get the JavaScript source file/line number, maybe position of an error which is intercepted by an uncaughtException handler?. I’m using Chrome. error.stack as mentioned here Node.js doesnt display entire error message on uncaughtException, is it possible? doesn’t work (only text “SyntaxError: Unexpected token .”, but I get all the infos in the Chrome debugger.
Web site is in building