I have a class User object. I am trying to load this object from the Database using Hibernate. My SQL statement is:  SELECT     users.uid               AS uid,     users.deleted           AS deleted,     users.username          AS username,     users.passwd            AS passwd,     users.disabled          AS disabled,     users.lockout           AS lockout,     users.expires           AS expires,     data_firstname.value            AS firstname,     data_lastname.value     AS lastname  FROM      ac_users as users LEFT JOIN     ac_userdef_data as data_firstname ON     users.uid = data_firstname.parentuid AND     data_firstname.fieldname like 'firstname' LEFT JOIN     ac_userdef_data as data_lastname ON     users.uid = data_lastname.parentuid AND     data_lastname.fieldname like 'lastname' WHERE     users.deleted = 0   My mapping for the User class is:  &lt;class name="com.agetor.commons.security.User" table="ac_users"&gt;     &lt;id name="uid" column="uid" type="long" &gt;         &lt;generator class="native"/&gt;     &lt;/id&gt;     &lt;property name="deleted" column="deleted" /&gt;     &lt;property name="username" column="username" /&gt;        &lt;property name="password" column="passwd" /&gt;     &lt;property name="firstname" column="firstname" /&gt;     &lt;property name="lastname" column="lastname" /&gt;     &lt;property name="disabled" column="disabled" /&gt;     &lt;property name="lockout" column="lockout" /&gt;     &lt;property name="expires" column="expires" /&gt;             &lt;/class&gt;    My problem is that the table ac_users does not have a column 'firstname' or 'lastname' These columns, only exist in my resultset from the SQL-join statement. They do also not exist in the ac_userdef_data table. There i have 2 colums: fieldname and value. and 2 rows: fieldname = 'firstname' with some value in the value column and another row with fieldname = 'lastname' with some value in the value column  How do i change my mapping file, so that Hibernate will understand that it needs to load the firstname and lastname column into my firstname and lastname fields on my POJO, while those columns dont actually exist on the referenced ac_users table.?
122597
Hello Stack Overflow Experts, i have need of your expertice:  I am trying to use Hibernate on an Existing DB. Currently im trying to load a User object and a list of UserData objects that go along.  in the DB the (simplified) layout is  |    User      |      |          UserData               | ----------------      ----------------------------------- uid | username |      | uid | parentuid | field | value |    So each User object matches all the UserData objects where UserData.parentuid = User.uid.  My User class mapping file      &lt;class name="com.agetor.commons.security.User" table="ac_users"&gt;     &lt;id name="uid" column="uid" type="long" &gt;         &lt;!--&lt;generator class="native"/&gt;--&gt;     &lt;/id&gt;     &lt;property name="username" column="username" /&gt;         &lt;list name="fieldData" cascade="all"&gt;         &lt;key column="parentuid" not-null="true" /&gt;         &lt;index column="parentuid" /&gt;         &lt;one-to-many class="com.agetor.commons.fields.FieldData"/&gt;     &lt;/list&gt;  &lt;/class&gt;    Mu  UserData mapping file      &lt;class name="com.agetor.commons.fields.FieldData" table="ac_userdef_data"&gt;     &lt;id name="uid" column="uid" type="long" &gt;     &lt;!--&lt;generator class="native"/&gt; --&gt;     &lt;/id&gt;     &lt;!--&lt;property name="parentuid" column="parentuid" /&gt;   --&gt;     &lt;property name="fieldname" column="fieldname" /&gt;     &lt;property name="value" column="value" /&gt; &lt;/class&gt;   So far i have tried many different configurations and all of them have had various degrees of failue. The code pasted here, does not work.    The parentuid property is commented out, because Hibernate gives a "Repeated column in mapping" error otherwise. Currently there is still a "Repeated column in mapping" on the uid field, i use for &lt;list-index /&gt; I do not understand where i specify that UserData.parentuid is the foreign key and that  the list should use User.uid as key.   I hope someone is able to help.    When you define both a One-To-Many and a Many-To-One, does this not make it Bi-Directional? The current working model, is Unidirectional and UserData does not have a reference to User. Your suggestion fails, because Hibernate could not find a get or set method for User on UserData.  Is it implied that, this code uses User.uid as a key and matches this against the UserData.parentuid column? Or is this fact specified somewhere else?    &lt;list name="fieldData" inverse="true"&gt;     &lt;key column="parentuid" not-null="true" /&gt;     &lt;one-to-many class="com.agetor.commons.fields.FieldData"/&gt;   &lt;/list&gt;   I am still learning Hibernate and working my way through documentation and examples i can find.
99190
I have a node object with image field named field_image. When I do  $node   -&gt;get('field_image')   -&gt;first()   -&gt;getValue()   I get array with some properties instead of entity object. The array looks like this:  'target_id' =&gt; string '8' (length=1) 'alt' =&gt; string '' (length=0) 'title' =&gt; string '' (length=0) 'width' =&gt; string '587' (length=3) 'height' =&gt; string '458' (length=3) '_loaded' =&gt; boolean true   '_accessCacheability' =&gt;      object(Drupal\Core\Cache\CacheableMetadata)[1092]       protected 'cacheContexts' =&gt;          array (size=0)           ...       protected 'cacheTags' =&gt;          array (size=0)           ...       protected 'cacheMaxAge' =&gt; int -1   Do I have to manullay load the file entity using target_id or there is a way to automatically get referenced entity object from instance of Drupal\image\Plugin\Field\FieldType\ImageItem?  Why the referenced entity is not accessible via getter? It could be lazy loaded if it's not available immediately.
16290
This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through the resources here and use them to shape more specific questions. To browse all canonical questions and answers, navigate to the  tag. This question and answer is owned by the community! If you can improve it and make it more useful, you're welcome to edit it. I am building a trigger, a unit test, or other Apex code. I'm working with sObject records, and trying to access related record information. For example, I might have a structure like this: Account a = new Account(Name = 'Test'); insert a;  Opportunity o = new Opportunity(Name = 'Donation', AccountId = a.Id); insert o;  System.assertEquals(o.Account.Name, 'Test', 'Correct Account associated'); // Assertion fails!  Or, in a trigger, I might be aiming for something like this: trigger ContactTrigger on Contact (after insert) {     for (Contact c : Trigger.new) {         if (c.Account.Name == 'Test') {             // Take some action here         }      } }  Why doesn't this work? Why am I getting null values, or NullPointerExceptions?
76988
To query a single record we have below two approach :  Approach 1. Assign record to a single Account variable as shown below:  Account accountToGet = [SELECT Name From Account where name = 'UniqueAccount' LIMIT 1];   With above line, it throws below error if no record founds : System.QueryException: List has no rows for assignment to SObject  Approach 2. Assign single record to a List variable as mention below :   List&lt;Account&gt; lstAccount = [SELECT Name From Account where name = 'Unknown Account'];    Even if SOQL returns no records, above line doesn't throws an error. We can use below line to avoid NULL errors.  if(!lstAccount.IsEmpty())     System.debug('No Error');   To handle NULL exception in Approach 1, we need to handle NULL exception in try....catch. It looks like an approach where we will error to occur and then handle it in try....catch.  With Approach 2, we can avoid exception to occur and without using try..catch.. also the code will work.  Based on above approaches, I think approach 2 is fine to prevent errors. Can anyone give me suggestion that why should not we use approach 2?
98355
With java.sql.ResultSet is there a way to get a column's name as a String by using the column's index? I had a look through the API doc but I can't find anything.
13630
I have a simple query:  SELECT u_name AS user_name FROM users WHERE user_name = "john";   I get Unknown Column 'user_name' in where clause.  Can I not refer to 'user_name' in other parts of the statement even after select 'u_name as user_name'?
55253
How do I check to see if a column exists in a SqlDataReader object?  In my data access layer, I have create a method that builds the same object for multiple stored procedures calls.  One of the stored procedures has an additional column that is not used by the other stored procedures.  I want to modified the method to accommodate for every scenario.  My application is written in C#.
68396
I want a way to establish which columns in a given database are joined via PK/FK relationships. I can return the PK/FK information for a given table via   SELECT *   FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS cu  WHERE EXISTS (     SELECT tc.*      FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc      WHERE tc.CONSTRAINT_CATALOG = 'MyDatabase'           AND tc.TABLE_NAME = 'MyTable'           /*AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY'*/         AND tc.CONSTRAINT_NAME = cu.CONSTRAINT_NAME); GO   but for a PK returned from such a query how do I establish the associated FK (assuming there is one)?  I know you can also get the referenced tables via:  SELECT CONSTRAINT_NAME = name,         FOREIGN_SCHEMA = OBJECT_SCHEMA_NAME(parent_object_id),         FOREIGN_TABLE = OBJECT_NAME(parent_object_id),         REFERENCED_SCHEMA = OBJECT_SCHEMA_NAME(referenced_object_id),         REFERENCED_TABLE = OBJECT_NAME(referenced_object_id)  FROM sys.foreign_keys WHERE OBJECT_NAME(referenced_object_id) = 'MyTable'; GO   but I am struggling now to get the explicit column references.  I am creating a script generator for QlikView. To generate the script I need the constraints and the associated links. I need all of the constraint information for any given column (if any).  I want to construct a database class that holds all the information for a given database. This class structure database.table.column.constraints will then be used to get the matches between different columns on PK/FKs.  Clearly some columns will have FKs only and in this case I also want to retrieve the PK information of the corresponding key; some will have only PKs and then I want the reverse. Some of course can have both.
24768
I really want to know more about the update, export and the values that could be given to hibernate.hbm2ddl.auto I need to know when to use the update and when not? And what is the alternative?  These are changes that could happen over DB:   new tables new columns in old tables columns deleted data type of a column changed a type of a column changed its attributes tables dropped values of a column changed    In each case what is the best solution?
56570
I have a database table that looks like:   create table answers(    id int not null,    question_id int not null,    answer text null )   This table was originally build by Hibernate using the @Lob attribute for the "answer" column.  I did not realize it at the time, but when setup that way, Hibernate stores an OID in the column instead of the actual text.  Everything works fine when I use Hibernate to retrieve the values since it automatically converts the OID to the CLOB string, however it is becoming a performance problem and I'd like to get rid of the OID.   select * from answers ID     QUESTION_ID     ANSWER =============================== 1       123             55123 2       234             51614 3       345             56127 should be ID     QUESTION_ID     ANSWER =============================== 1       123             Male 2       234             203-555-1212 3       345             555 Main St. New York, NY    My desire is to add an extra column to the table "ANSWER_VALUE TEXT" and do something like below to get the actual value into the table, then change Hibernate around to not use the @Lob designator   update answers set ANSWER_VALUE= getValueFromOID(ANSWER)   Does that "getValueFromOID" function exist?  If not, could I get some pointers on how to create one or at least how to fetch the actual value of an OID?  Thanks
109966
i have posted this question earlier but i'm not getting the proper solution  please read the requirement carefully.* i have a custom object Integration__c and it has fields username__c,password__c,url__c,account__c(lookup field) fields. and Integration__c has some records.   here comes my requirement is i have created a trigger on Case object as after insert event. 1.when case creating must be select an account lookup field with one salesforce account. 2.now after clicking the save button it will check with Integration__c custom object records with the matching account field in case record. 3.if any record is in the Integration__c is match with the case object account field then returns the field values of integration__c from that record only. for that i have developed a trigger on Case : trigger Type on Case (after Insert) {      List&lt;ID&gt; cIds = new List&lt;ID&gt;();           Set&lt;String&gt; lst_accountName = new Set&lt;String&gt;();     List&lt;String&gt; allaccountnamesList = new List&lt;String&gt;();          //Map&lt;ID, Integration__c&gt; mapIds = new Map&lt;ID,  Integration__c&gt;();                           for(Case cObj : Trigger.new){                        if(cObj.Account.Name != null &amp;&amp; cObj.IntegrationTo__c != null){                                cIds.add(cObj.Id);                                } lst_accountName.add(cObj.Account.Name);                        }allaccountnamesList.addAll(lst_accountName );                  List&lt;Case&gt; cas = Trigger.new;          List&lt;Integration__c&gt; listAll = [SELECT id,name,username__c,password__c,URL__c,account__c,integrationwith__c FROM Integration__c ];                      for(Case c : cas  ){             for(integer i=0; i&lt;=listAll.size();i++){                     if(listAll.get(i).IntegrationAccount__c.contains(c.Account.Name)){                                                                                                                                          String name = listAll.get(username__c);                      String pwd = listAll.get(password__c);                      String url = listAll.get(URL__c);                                                                        }        }    } }  How can I get the only matched account field value on case with any of the records in Integration__c, then return the record  details from that record only? when i saving the above code it shows an error called :  Error: Compile Error: Variable does not exist: username__c at line 32 column 48
78923
I'm dealing with nullable values in a column of a table, i'm wondering why this:  with cte as (     select 'c1'::text as c1,null::text as c2     union     select 'c2'::text as c1,null::text as c2 ) select * from cte where c2 is null   returns a result set with the two "rows" having a null value in c2; comparting to this query:  with cte as (     select 'c1'::text as c1,null::text as c2     union     select 'c2'::text as c1,null::text as c2 ) select * from cte where c2 = null   that returns an empty result set!!  so it looks like that field is null is actually different from field = null? the question is... is there "null-compatible operator" to use? so i can write the comparision like: column_name = $1 and argument $1 can be a not null or null value. IF $1 is a null value then it will semantically equals to write as IS NULL, ELSE (if $1 is not a null value) then it would be semantically equals to = $1.  P.D: This question also applies to the case is NOT NULL versus &lt;&gt; NULL
123622
How how do I query recent account views and group by LastViewedDate    SELECT Id, Name                 FROM Account                ORDER BY Name DESC limit 10 FOR VIEW   I used to have it like this, but my test case is keep failing  SELECT SELECT Id, Name, LastModifiedDate                         FROM account                         WHERE LastModifiedDate !=null ORDER BY LastViewedDate DESC limit 10  static testmethod void testOppExt_TestMethod(){        Opportunity testOpp = new Opportunity(Name = 'TestOpp', StageName='Test', CloseDate = Date.today());       insert testOpp;        Account testAcc = new Account(Name = 'Test Account');       insert testAcc;        Contact con = new Contact(LastName='Test',AccountId=testAcc.id);       insert con;        Test.startTest();       OppExt testCon = new OppExt();       Contact conn = testCon.contact;       Account  Accn = testCon.acc;       Test.stopTest();     }   Error Message   Component Errors API Name Type Line Column Error Message 0 0 , Details: Average test coverage across all Apex Classes and Triggers is 0%, at least 75% test coverage is required. 0 0 SiteRegisterControllerTest.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 SiteLoginControllerTest.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 SiteRegisterController.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 testnewOpportunityController.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 SiteLoginController.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 testOppExt.null(), Details: line -1, column -1: Previous load of class failed: oppext null 0 0 OppExt.null(), Details: line 32, column 17: No such column 'LastViewedDate' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. null
8309
I need to query the database to get the column names, not to be confused with data in the table.  For example, if I have a table named EVENT_LOG that contains eventID, eventType, eventDesc, and eventTime, then I would want to retrieve those field names from the query and nothing else.  I found how to do this in:        But I need to know: how can this be done in Oracle?
3723
I'm trying to perform the following multilevel relationship query.   SELECT ID, SystemModstamp, Product__r.Catalog__r.Active__c  FROM Journal__c      WHERE SystemModstamp &gt; 2013-10-02T00:00:00.000+0000  AND SystemModstamp &lt; 2013-10-05T00:00:00.000+0000    In the Product__r.Catalog__r.Active__c column I'm getting a value of [object Object] for every single record. I can substitute any field name from the Catalog__c object and get the same response. Does anyone know why this is happening or how to get the field's actual value?
25040
I have to create a report on some student completions. The students each belong to one client. Here are the tables (simplified for this question).  CREATE TABLE  `clients` (   `clientId` int(10) unsigned NOT NULL auto_increment,   `clientName` varchar(100) NOT NULL default '',   `courseNames` varchar(255) NOT NULL default '' )   The courseNames field holds a comma-delimited string of course names, eg "AB01,AB02,AB03"  CREATE TABLE  `clientenrols` (   `clientEnrolId` int(10) unsigned NOT NULL auto_increment,   `studentId` int(10) unsigned NOT NULL default '0',   `courseId` tinyint(3) unsigned NOT NULL default '0' )   The courseId field here is the index of the course name in the clients.courseNames field. So, if the client's courseNames are "AB01,AB02,AB03", and the courseId of the enrolment is 2, then the student is in AB03.  Is there a way that I can do a single select on these tables that includes the course name? Keep in mind that there will be students from different clients (and hence have different course names, not all of which are sequential,eg: "NW01,NW03")  Basically, if I could split that field and return a single element from the resulting array, that would be what I'm looking for. Here's what I mean in magical pseudocode:  SELECT e.`studentId`, SPLIT(",", c.`courseNames`)[e.`courseId`] FROM ...
2033
I am working on a third party database.  When I try to view the definition of a view by right clicking, CREATE TO and then to NEW QUERY EDIT WINDOW, I am getting an error:     This property may not exist for this object or may not be retrievable   due to insufficient access rights. The text is encrypted.