Basic JPA native query design question

Is this ok to reuse the lookup of the EntityManager and not close it?
//Database call
try {
Query query = Resource.getEntityManager().createNativeQuery(sqlStatement);
results = query.getResultList();
catch(Exception pExc) {
LogTool.error("Error running this query CALENDAR sqlStatement:" + sqlStatement);
public final class Resource {
private static EntityManager entityManager;
public static EntityManager getEntityManager() throws NamingException {
if(entityManager==null) {
Context ctx = new InitialContext();
entityManager = (EntityManager) ctx.lookup(JPA_PERSISTENCE_CONTEXT);
return entityManager;
}

917903 wrote:
Well, it felt silly in every instance to do this same lookup everytime A. so I made the function B.First case
1- It represents a resource to which you shouldn't hold onto.
2- It doesn't represent a resource.
If the first then you should always look it up. If the second it doesn't matter if you look it up every time. So everytime wins for that case.
Second case only applies if there is a measurable and significant performance impact and it does NOT represent a resource (so 2 from above.) If that is the case then hanging onto it makes sense. But I doubt that it would have such an impact.
I wouldn't be surprised that if your JEE container allows you to redefine the pool while the app is running that you would find that choice 1 above is what is going on.

Similar Messages

  • Jpa native query returns only first character of a field

    Hi,
    I've a JPA native query that returns two fields from my oracle database. The first field is a CHAR(2) field with two char values in it, like 'OZ' etc.
    The problem is, as soon as the query is executed it returns only first character of field1. If the actual value of field1 is like 'OZ' then it returns only 'Z'.
    Query nativeQueryForProfileInfo = getManager().createNativeQuery(queryToRun);
    List list = nativeQueryForProfileInfo.getResultList();
    Please help,
    thanks

    There could be several explanations here and it's difficult to say without having more details, possibilities are
    There is something wrong with your display logic.
    There is something wrong with your mapping.

  • Bi Query Design Question

    Hi,
                I have a question regarding a query design issue I was faced with today. I was asked to designed a Query, however all the fields required are all defined as characteristics but I would like to display one as a key figure. I would have a characteristic for a row, the column also for a characteristic and have another characteristic displayed instead of the key figured…… Is that possible?
    Thanks for any feedback

    Hi Serge,
    This question would be more appripriate -- and you will get a quicker answer -- in the BI Forums.  Please open your question there.
    Best Regards,
    Matt

  • Basic Difference in Query Designer

    Hi All,
    Can anybody let me know the difference between Characteristic Restriction and "Default Values" tabs under the Filter section in Query Designer.
    I am able to restrict the same on both these tabs.I am able to use variables on both side even constants on both sides.
    Kindly let me know.

    Hi......
    Characteristic Restriction
    Here u define the characteristic filter values..........which apply to the entire resultset........This cannot be change.....
    Suppose u restrict Plant .......to show within 1000 to 5000.............May be the actual Plant range  is from 1000 to 8000...........But in the entire result on value for the Plant within range 1000 to 5000 will be displayed ........
    Default Values
    In this pane u define the characteristic filter values which should be used for the initial view of the result set..The user may choose to modify these filters in the result..........
    Suppose you set default value for Plant 1000..........then the initial screen will only display data related to Plant 1000......
    Hope this helps......
    Regards,
    Debjani.......

  • Query design question (NW04s)

    In query designer, how do I hide a column that has no data. I know how to suppress zero result columns, but these columns are not zero because they had no data.
    Can this be done using a local formula?

    Hi Raynald,
    Yes you can do this by restriction. I mean you restrict the report only display for the column that has a data.
    How you do this :
    1. Open your query.
    2. Right click for the characteristic (column), choose restrict.
    3. Choose for fix values, and singles value for selection type.
    4. (there will be 2 area) You restrict it by choose no-data / symbolized by # (move it from left to right pane).
    5. (After moving it to right pane) You right click to that symbol then choose exclude from selection in the context menu.
    If you have already made it, the column that has no data will be hidden.
    Hopefully it can help you.
    Regards,
    Niel.
    award points if it helps you.

  • Query design question: multiple plan versions in single column

    I have a standard financial statement query with current month "Actual" restricted to Value Type 10 and current month "Plan" using Value Type 20.  This scenario is repeated for year-to-date Actual and Plan along with $ and % variance calculations.   Until recently we were only loading plan version so I had no reason to restrict the plan to version 0 Actual/Plan.
    We are now loading an alternate plan version, Version 1, and I would like to report both versions in the same query.  I though I could just bring in "Version" as a Free Characteristic to easily switch between version 0 and 1 but that didn't work as expected. 
    With "Version" as a filter item my Plan amount will report both plan versions combined which is fine and when "Version" is filtered to the alternate version 1 Plan correctly displays the alternate amount, in both cases Actual is unchanged and displays correctly.   The problem is when I change the filter to just show Version 0 which is defined as "Actual/Plan".  When version 0 is selected the Plan amount displays correctly but ALL Actual values disappear.
    No Version filter set = Actual/Plan and Plan Version 1 combined correctly.   Actual displays correctly.
    Filter set to 1 and 0  = Actual/Plan and Plan Version 1 combined correctly.   Actual displays correctly.
    Filter set to 1 = Plan Version 1 only.  Actual displays correctly.
    Filter set to 0 = Plan Version 0 only.  No actual data is displayed.
    Is there a better way of displaying multiple plan versions in a query or will I have to add additional columns for each plan version?
    Thanks for the ideas,
    Jeff

    Thanks Amit that was the help I needed.
    I added "Version" to every actual Key Figure and made each a Constant Selection.  I also added Version as a Free Characteristic of the query for a filter.
    By adding Version to each Key Figure no matter which plan version I select in the Version filter Actual data alway remains correct and just my Plan column changes to show the plan version I selected.
    Thanks for your help,
    Jeff
    Edited by: Jeff Mayfield on Nov 11, 2009 11:51 PM

  • Query design question

    I am writting a query against 0IC_C03 (Material stocks/movements).  To simplify the situation, here is what I have: material and posting date in rows, issue total stock and receipt total stock in columns. I'd like to add another column to display the LAST DATE of all movements for that material.  Can I do it?  How?  Any suggestions or comments will be greatly appreciated.
    Thanks!
    Tim

    Hi,
    You can directly drag and drop on Key figures then, data (keyfigure  values) will be displayed date wise in columns.
    Hope this helps..............
    Rgs,
    I.R.K

  • Query design question - Adding Key Figures (NW04s)

    I have a simple query defined as follows:
    -- Rows:
    2 characteristics with result 'Always suppress'
    -- Columns:
    1 characteristic (posting period)
    1 Structure with 2 calculated key figures
    I want to add a formula that adds all the CKF's on each row and displays only once on the far right of row. Best method?

    Hi,
    You can go ahead with restrictions for keyfigures with two variables. One variable is for ready for input and another variable with customer exit which should pick the first month of the year entered in the previous variable.
    Ex: if a user enter a month for 02.2008, then the customer exit will pick the year based on the enterd month and finds first month of that year and display the data with month ranges.
    In the variable you have take value ranges.
    Reg
    Pra

  • Difference Beetween Query Designer and Adhoc Query Designer

    Hello!
    can any one explain me what exactly is Adhoc query designer and how is it different from  Bex Query designer. can you please provide me links for Adhoc query designer (not to Bex query designer)
    with regards
    ashwin

    Hi Ashwin,
    See this link:
    http://help.sap.com/saphelp_nw04/helpdata/en/1f/03223c5f00612be10000000a11402f/content.htm
    Basically the Adhoc query designer is a web item that you can include in a web template to allow the user to create or change queries in the web environment. It has some limitations like you cannot use variables, and can only use one structure.
    Hope this helps...

  • Query Design/Implementation Question

    Hi,
    I have to query the database based on different input values from a JSP page. So, A user can query the database based on one or more fields. My question to you is what would be an efficient way to write the queries or implement this using JDBC. Should I write PreparedStatements for every possible combination of the query fields. Should I write stored procedures ? I had problems with the PreparedStatement earlier and I still do, so just to keep my developement going I wrote a stored procedure. If you read my previous post you can read the whole story.
    So, this is more of a design question. Let the ideas flow.
    Any help or suggestion will be appreciated.
    Thanks,
    Prasoon

    Hi Justin,
    This I got from an earlier post on this forum and you said that doing this was a very bad idea. Why ? I am doing this just as a workaround to my current problem.
    So, basically I would have a temporary table for every query field in my JSP page. This table I would create in separate stored procedures and then finally do an AND to get the result ?
    This feels dirty to me too but can u suggest a better way ?
    Thanks,
    Prasoon
    stored procedure, temporary table, and result sets Nov 6, 2003 6:39 PM
    Reply
    Pls, Help me with the folloing questions:
    1. Is it possible to declare and use temporary tables in a stored procedure? How?
    2. Is it possible to return a result set, or recordset from a stored procedure? How?
    These might be a very basic one, but as a beginer in Oracle Databse, I am having hard time to find out good source of technical materials.
    Justin Cave
    Posts: 5,786
    OTN Member Since: Oct, 1999
    Re: stored procedure, temporary table, and result sets ( In Reply To : stored procedure, temporary table, and result sets ) Nov 6, 2003 7:17 PM
    Reply
    1) You certainly can declare and use temporary tables in a stored procedure. On the other hand, doing so strikes me as a manifestly bad idea, so I would strongly caution you not to. If you explain a bit about what you're trying to accomplish, I'm sure there are better ways.
    If you did want to create temporary tables in a stored procedure, you'd have to use dynamic sql, i.e.
    execute immediate 'create temporary table foo...'
    2) You can return resultsets from a stored procedure by declaring an OUT parameter which is a REF CURSOR.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • JPA  using native query - distinct

    Hi All,
    Kindly suggest on the following,
    I am facing issues on using the distinct keyword in JPA, Ful details on the following OTN thread.
    JPA  using native query - distinct
    Any help is much appreciated
    VR

    Any ideas ?

  • Query designer in EXCEL question

    Hi!
    I have a question about query designer in excel.
    I want SQL query to have in WHERE clause OR instead of AND (which is default), so the query would be like these:
    <b>ORIGINAL:</b>
    SELECT
    D1~SID_ZKAZALNIK AS S____590
    COUNT( * ) AS 1ROWCOUNT
    SUM( F~/BIC/ZPLANKA2 ) AS ZPLANKA2
    SUM( F~/BIC/ZVREDKA2 ) AS ZVREDKA2
    FROM
    FROM
    /BIC/FZKAZAL AS F
    JOIN
    /BIC/DZKAZAL1 AS D1
    ON
    F~KEY_ZKAZAL1
    = D1~DIMID
    JOIN
    /BIC/DZKAZALT AS DT
    ON
    F~KEY_ZKAZALT
    = DT~DIMID
    JOIN
    /BIC/DZKAZALP AS DP
    ON
    F~KEY_ZKAZALP
    = DP~DIMID
    WHERE
    <b>WHERE
    DT~SID_0CALQUARTER
    = 20044
    ) ) AND  ( (
    DP~SID_0RECORDTP
    = 0
    ) ) AND  ( (
    DP~SID_0REQUID
    <= 1060
    ) ) ) )</b>*** GROUP BY
    GROUP BY
    D1~SID_ZKAZALNIK
    DB-SPECIFIC HINTS
    &SUBSTITUTE LITERALS&
    <b>WHAT I WANT:</b>
    SELECT
    D1~SID_ZKAZALNIK AS S____590
    COUNT( * ) AS 1ROWCOUNT
    SUM( F~/BIC/ZPLANKA2 ) AS ZPLANKA2
    SUM( F~/BIC/ZVREDKA2 ) AS ZVREDKA2
    FROM
    FROM
    /BIC/FZKAZAL AS F
    JOIN
    /BIC/DZKAZAL1 AS D1
    ON
    F~KEY_ZKAZAL1
    = D1~DIMID
    JOIN
    /BIC/DZKAZALT AS DT
    ON
    F~KEY_ZKAZALT
    = DT~DIMID
    JOIN
    /BIC/DZKAZALP AS DP
    ON
    F~KEY_ZKAZALP
    = DP~DIMID
    WHERE
    <b>WHERE
    DT~SID_0CALQUARTER
    = 20044
    ) ) <b>OR</b> ( (
    DP~SID_0RECORDTP
    = 0
    ) ) <b>OR</b>  ( (
    DP~SID_0REQUID
    <= 1060
    ) ) ) )</b>*** GROUP BY
    GROUP BY
    D1~SID_ZKAZALNIK
    DB-SPECIFIC HINTS
    &SUBSTITUTE LITERALS&<b></b><b></b>
    Is there a way to change filter from AND to OR where u need that in visual query designer in Excel????
    I need these becouse i want to say smth. like that ... SELECT data FROM some cube WHERE date = 10/2004 OR date_q = 3/2004 OR month = 11 OR year = 2003

    Thanks for reply Roberto!
    Do u think with that? :
    Create 3 different queries on worksheet and than copy values in excel to another worksheet manualy?
    If that, then this is not an option for me, becouse i need joust one query.
    Is there another option?

  • Some question about the query designer

    hello, dear all,
    I am a new comer of here, and I am intersting in BI, but I have no basic knowledge about it.
    so I just want someone could give me some advice about it.
    our boss need I do the developer about the query designer,  I just have searched in this forum. but nothing founded for I am a new comer here,
    I heard there are some training document of the query designer, could someone give me the URL, thanks.

    Hi,
    Query desinger is used to develop a Query, Query can be created on following data targets
    -Info Cube
    -DSO
    Virtual data target
    -MultiCube
    -Infoset
    -Multiprovider
    We have 5 section in query designer
    - Infoprovider : where we select the data target , on which report to be created
    -Filter : to restrict value at infoprovider level ( if you want data for year 2008, for example)
    -Free Characterstic : this allow you to drill down
    -Columns : char/keyfigs to be display in columns can be added here
    Row: key/char to be display in Rows can be added here
    gv me ur mailid i will let u have Bex manual,
    I would suggest , if you have any IDES ( training ) system , where you can log in and then go to RRMX,
    and try to create new query and add any data target ( which is already created ) and then drag and drop the char/key fig to the required section ,
    save it and execute it .....
    if you play arround and see the output , that would help u to understand how to work with query designer.
    Hope this helps
    Sukhi
    Edited by: Sukhvidner Singh on Nov 4, 2009 5:36 PM

  • Question about calculation example with Query Designer

    Hi guys,
    I have to calculate within columns and rows and I am not familiar with the settings in Query Designer that could be done to achieve the results.
    For example:
    Payments----
    Delay -
    Weighted Delay
    1000USD--10 days--
    10000
    2000USD--20 days--
    40000
    3000USD--xxx--
    50000 (this is the sum row)
    The column marked with the xxx is calculated with the sum of weighted delay divided by the sum of payments (50000 / 3000).
    Has anybody an idea how the sum row can be calculated separately?
    Thank you for suggestions!
    Edited by: saplaz on Jul 13, 2010 8:47 AM
    Edited by: saplaz on Jul 13, 2010 9:08 AM

    Hi,
    Assuming you have the Payments Infoobject in the rows and WD Infoobject in the columns; Delay as a formula object.
    > Payments----
    Delay -
    Weighted Delay
    > 1000USD--10 days--
    10000
    > 2000USD--20 days--
    40000
    > 3000USD--xxx--
    50000 (this is the sum row)
    > The column marked with the xxx is calculated with the sum of weighted delay divided by the sum of payments (50000 / 3000).
    You may try this workaround of using
    NODIM( SUMCT(WEIGH_DELAY) / SUMCT(PAYMENTS) )
    on a formula variable. (In this case, the assumption is you have not static type-restricted the rows/cols) If you find any hinderances in the default approach, you may check this out as a formula & insert this at the cell editor level.
    If not, use a simple formula variable; here define the replacement path as 0(N) for your Payments. (N being the # of digits)
    Use a simple calculation:
    SUMGT(WD)/FV
    But you may not get an result o/p in the last row, as the values are not linked (sans relation with Payments). as it will return a X for the delay in the Result row.
    Pls. let me know know if this works or some sample o/p if the initial assumption was wrong.
    Thanks,
    Arun Bala

  • Webi: BW Query design best practice question

    The scenario is as follows:
    SAP NetWeaver BW 7.01 SPS3
    Business Objects Enterprise XI 3.1 Fix Pack 1.2
    SAP Integration Kit XI 3.1
    Webi report built off of a BW Query. Based on the versions listed above, the MDX statement generated should only pick up only the fields listed in the query panel in Webi, not necessarily every field in the underlying BW query.  Having said that, does it matter what fields are in the Free CHAR or in the rows in the underlying BW Query??  I heard a suggestion that all fields should be put in the Free CHAR panel of the BW Query Designer but I don't see the value add of that approach.  Any thoughts?
    -Brad

    Hi,
    it does not matter if the items are Free Characteristics or rows or columns.
    for best practices here some material:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/008d15dc-f76c-2b10-968a-fafe5a121129
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b0320722-741c-2c10-afab-93b5c0fc7e96
    Ingo

Maybe you are looking for