SQL to JPA @NamedQuery Conversion
I'm looking for an intelligent way to convert this SQL statement into
@NamedQuery --if there is a way at all?
SELECT MONTH(dateField), sum(value) FROM mydb.records where status ='paid'
group by MONTH(dateField) order by MONTH(dateField);
I have a JPA @Entity called Record (Hibernate). This details all invoices
in the system that are created on daily basis. There will be many entries
per month. Each record will have a status of paid, overdue, value, and
lots of other info such as name and address of customer and so on etc.
The above statement basically summarises all the data on a month by month
basis and sums the value of all paid invoices per month giveing a summary
of all invoices paid in January, all paid in Feb and so on.....The result
looks somethings like:
datefield value
1 4500
2 5500
3 5669
The only way I can think of doing this using JPA @NamedQuery is to select
all records in the table that are of status 'pai'd and then use my Java
code to do the sorting, ordering and addition in a rather slow and ugly
fashion! Is there a clever way I can do this with @NamedQuery?
Thanks
Bomaster
Thursday, 3 October 2013
Wednesday, 2 October 2013
Java: java.lang.NumberFormatException
Java: java.lang.NumberFormatException
do{
System.out.println("Input:\n(Consider the input is from the
sensor)\n");
temperature = Integer.parseInt(br.readLine());
examineTemperature(temperature);
System.out.println("Does the sensor wanna continue giving
input?:(y/n)\n");
c = (char) br.read();
}while(c!= 'N' || c!='n');
I don't understand where i went wrong because I am getting an error as
shown below in eclipse:
Input:
(Consider the input is from the sensor)
45
Temperature is 45 in celcius. Hmmm...
Thats 113 in Farenheit...
***The weather is niether too hot nor too cold***
Does the sensor wanna continue giving input?:(y/n)
N
Input:
(Consider the input is from the sensor)
Exception in thread "main" java.lang.NumberFormatException: For input
string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at tempdetection.main(tempdetection.java:33)
I got my answer and then its throwing this exception... If i press
Anything other than N it loops but again throws this exception.. Why so??
do{
System.out.println("Input:\n(Consider the input is from the
sensor)\n");
temperature = Integer.parseInt(br.readLine());
examineTemperature(temperature);
System.out.println("Does the sensor wanna continue giving
input?:(y/n)\n");
c = (char) br.read();
}while(c!= 'N' || c!='n');
I don't understand where i went wrong because I am getting an error as
shown below in eclipse:
Input:
(Consider the input is from the sensor)
45
Temperature is 45 in celcius. Hmmm...
Thats 113 in Farenheit...
***The weather is niether too hot nor too cold***
Does the sensor wanna continue giving input?:(y/n)
N
Input:
(Consider the input is from the sensor)
Exception in thread "main" java.lang.NumberFormatException: For input
string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at tempdetection.main(tempdetection.java:33)
I got my answer and then its throwing this exception... If i press
Anything other than N it loops but again throws this exception.. Why so??
Preventing user from switching TabItem + Nasty bug?
Preventing user from switching TabItem + Nasty bug?
I have some validation logic and a TabControl. I want to prevent the user
from switching tabs when the current one contains some error.
I have found some people asking the same and some people gave good answers
as you can see here.
TabControl- preventing user from changing the selected tab: MessageBox
causing bug
HOWEVER, as Fredrik Hedblad tell, when a MessageBox is shown while the
selection is being canceled, the whole thing breaks down. It experiences a
strange behavior. The event stops being raised (apparently) and if you
minimize and restore the Window, it suddenly raised without interacting!!
Can somebody shed some light on this? Thanks a lot!!!
I have some validation logic and a TabControl. I want to prevent the user
from switching tabs when the current one contains some error.
I have found some people asking the same and some people gave good answers
as you can see here.
TabControl- preventing user from changing the selected tab: MessageBox
causing bug
HOWEVER, as Fredrik Hedblad tell, when a MessageBox is shown while the
selection is being canceled, the whole thing breaks down. It experiences a
strange behavior. The event stops being raised (apparently) and if you
minimize and restore the Window, it suddenly raised without interacting!!
Can somebody shed some light on this? Thanks a lot!!!
Understanding default behavior of branching?
Understanding default behavior of branching?
db 11gxe and apex 4.x
i created a master detail page , there are buttons on it by default , like
(cancel,delete,apply changes) and two buttons for getting the next order
and the previous one --there a master table for orders .
there are also branches created by default for the button getting the next
order and the button getting the previous one (the branch is conditional
ofcourse) -- the condition is when-button-clicked .
these branches are created automatically because the buttons are exist ,
and there are conditions which are "when-button-clicked" --just this
condition .
-- what i do not understand is that there are other buttons like "delete ,
cancel , apply changes" , and there were no branches created for them like
the other buttons which i mentioned above ,
although they also navigate like the other buttons , and the condition is
when-button-clicked as well ?
why in the first situation there are branches created automatically , and
in the last situation there are not ??
thanks in advance
db 11gxe and apex 4.x
i created a master detail page , there are buttons on it by default , like
(cancel,delete,apply changes) and two buttons for getting the next order
and the previous one --there a master table for orders .
there are also branches created by default for the button getting the next
order and the button getting the previous one (the branch is conditional
ofcourse) -- the condition is when-button-clicked .
these branches are created automatically because the buttons are exist ,
and there are conditions which are "when-button-clicked" --just this
condition .
-- what i do not understand is that there are other buttons like "delete ,
cancel , apply changes" , and there were no branches created for them like
the other buttons which i mentioned above ,
although they also navigate like the other buttons , and the condition is
when-button-clicked as well ?
why in the first situation there are branches created automatically , and
in the last situation there are not ??
thanks in advance
Not able to change folder owner rights with chown on Mac OS X Server
Not able to change folder owner rights with chown on Mac OS X Server
I have an external hard drive used for storing and sharing files with
other computers in the network. After a power failure I had issues logging
into the workgroup manager and I noticed that LDAP wasn't running anymore.
I had to recreate the Open Directory Master settings and it seems that all
my previous user data and permission settings were lost.
Now I was able to get into the workgroup manager again and created new
users and put them in a new group ADMINISTRATION. I would now like to give
permissions to this group to read & write files on some folders of the
external drive.
I wanted to start doing that, but noticed that the Admin user (which I use
to login to the Mac OS X server) had no access to the folders on the
external drive. Therefore I thought I had to grant the Admin user read &
writing rights to those folders first.
So I open the Terminal and navigate to the Datadisk and use the command:
sudo chown -R Admin .
This should change the owner rights recursively I thought. When the
command was finished without errors, I checked the Datadisk and strange
enough I now have access to some folders and not to other folders. So I
navigated in the Terminal to one particular folder to test and used the
same command, but nothing changes.
What could be wrong? Hope somebody can help out, because I don't have
access to my data folders anymore so I'm not able to work at the moment.
Thanks in advance!
I have an external hard drive used for storing and sharing files with
other computers in the network. After a power failure I had issues logging
into the workgroup manager and I noticed that LDAP wasn't running anymore.
I had to recreate the Open Directory Master settings and it seems that all
my previous user data and permission settings were lost.
Now I was able to get into the workgroup manager again and created new
users and put them in a new group ADMINISTRATION. I would now like to give
permissions to this group to read & write files on some folders of the
external drive.
I wanted to start doing that, but noticed that the Admin user (which I use
to login to the Mac OS X server) had no access to the folders on the
external drive. Therefore I thought I had to grant the Admin user read &
writing rights to those folders first.
So I open the Terminal and navigate to the Datadisk and use the command:
sudo chown -R Admin .
This should change the owner rights recursively I thought. When the
command was finished without errors, I checked the Datadisk and strange
enough I now have access to some folders and not to other folders. So I
navigated in the Terminal to one particular folder to test and used the
same command, but nothing changes.
What could be wrong? Hope somebody can help out, because I don't have
access to my data folders anymore so I'm not able to work at the moment.
Thanks in advance!
Tuesday, 1 October 2013
Python - file closed within with statement
Python - file closed within with statement
I have two versions of similar code, one works, the other doesn't:
version 1
#some code
with open('file', 'w') as f:
f.writelines(new_lines)
with open('file') as f:
i = 0
for line in f:
i = i + 1
if i != 5 and i != 18 and i != 27:
row.append(line)
version 2
# some code
with open('file', 'w') as f:
f.writelines(new_lines)
i = 0
for line in f:
i = i + 1
if i != 5 and i != 18 and i != 27:
row.append(line)
When executing the version 2 code, I got an error which says that the file
is not open. I got confused because obviously the code is still in the
with statement. Does the file get closed automatically right after the
f.writelines() method?
I have two versions of similar code, one works, the other doesn't:
version 1
#some code
with open('file', 'w') as f:
f.writelines(new_lines)
with open('file') as f:
i = 0
for line in f:
i = i + 1
if i != 5 and i != 18 and i != 27:
row.append(line)
version 2
# some code
with open('file', 'w') as f:
f.writelines(new_lines)
i = 0
for line in f:
i = i + 1
if i != 5 and i != 18 and i != 27:
row.append(line)
When executing the version 2 code, I got an error which says that the file
is not open. I got confused because obviously the code is still in the
with statement. Does the file get closed automatically right after the
f.writelines() method?
addFirst() in a custom LinkedList
addFirst() in a custom LinkedList
I'm working with a LinkedList of customLinkedLists and I'm having some
problems with the implementation of my AddFirst method.
Here's the method,
public void addFirst(GenericType data)
{
Node<GenericType> toAdd = new Node<GenericType>(data);
if(sizeCounter != 0)
{
toAdd.next = head;
head = toAdd;
sizeCounter++;
} else {
head = add;
tail = add;
toAdd.next = null;
sizeCounter++;
}
}
The problem is this increments the size correctly every time i call it,
but when I try to print out the values, it throws a null pointer
exception. I know there's a problem in the way I'm setting the head/tail
pointer but I cant figure out what it is exactly.
I'm working with a LinkedList of customLinkedLists and I'm having some
problems with the implementation of my AddFirst method.
Here's the method,
public void addFirst(GenericType data)
{
Node<GenericType> toAdd = new Node<GenericType>(data);
if(sizeCounter != 0)
{
toAdd.next = head;
head = toAdd;
sizeCounter++;
} else {
head = add;
tail = add;
toAdd.next = null;
sizeCounter++;
}
}
The problem is this increments the size correctly every time i call it,
but when I try to print out the values, it throws a null pointer
exception. I know there's a problem in the way I'm setting the head/tail
pointer but I cant figure out what it is exactly.
Subscribe to:
Comments (Atom)