null

Hibernate handle long 0 value instead of NULL in ManyToOne relations

孤者浪人 提交于 2020-01-03 10:39:09
问题 I use Hibernate to access to a legacy DB. For some tables the parent-child reference integrity is not enforced, and the long 0 value is used instead of NULL for some "parent" columns in child tables to denote "no parent". I still want to use these relations in @ManyToOne and @OneToMany fields, but get EntityNotFound error since the 0 value does not correspond to any record in master table. What are my options? 回答1: Use the NotFound annotation: @NotFound(action = NotFoundAction.IGNORE) See

Why does Assigned return true for uninitialized variables?

柔情痞子 提交于 2020-01-03 09:46:25
问题 I read many posts on forum about pointers, Assigned function, Free function, FreeAndNil function, etc... I already know Free function don't remove the pointer reference to an object assigned and FreeAndNil does it... All posts I read treat this subject considering Create method already was executed, or in other words, considering an object already created. My question is: Why Assigned function returns true for a uninitialized object variable ? Follow an example: procedure TForm1.FormCreate

How to handle null values in linq?

ⅰ亾dé卋堺 提交于 2020-01-03 08:55:08
问题 recordsList.ListOfRecords = new StudentRecordsBAL() .GetStudentsList() .Select(q => new StudentRecords() { _RollNumber = q._RollNumber, _Class = q._Class, _Name = q._Name, _Address = q._Address, _City = q._City, _State = q._State, _Subjects = q._Subject, _AttendedDays = new AttendanceBAL() .GetAttendanceListOf(q._RollNumber) .Where(date => date != null) .Select(date => new DateTime(date._Date.Year, date._Date.Month, date._Date.Day)) .Distinct() .ToList(), _AttendedSubjects =

Attempting to access a null pointer [duplicate]

▼魔方 西西 提交于 2020-01-03 08:35:11
问题 This question already has answers here : C++ standard: dereferencing NULL pointer to get a reference? [duplicate] (5 answers) Why dereferencing a null pointer is undefined behaviour? (12 answers) Closed 6 years ago . #include <iostream> int main() { int* i = 0; int x = (*i); std::cout << x; } The above program will crash when I compile and run it using Visual Studio 2010 and I know it crashes because I set the pointer to 0. What I would like to know, is accessing a null pointer in C++ defined

Casting null doesn't compile

孤者浪人 提交于 2020-01-03 08:28:02
问题 accidentally at work I wrote the following line of code: string x = (object) null; // It was var x = (object)null and I changed from var to string instead of // object x = null; This gave me a compilation error similar to this: Can't cast source type object to target type string Why? Isn't null just a bunch of zeros pointing to "nowhere" memory address, no matter what the type is? 回答1: The question here is basically "why does the compiler not take into account the fact that it knows that the

Casting null doesn't compile

北城以北 提交于 2020-01-03 08:27:08
问题 accidentally at work I wrote the following line of code: string x = (object) null; // It was var x = (object)null and I changed from var to string instead of // object x = null; This gave me a compilation error similar to this: Can't cast source type object to target type string Why? Isn't null just a bunch of zeros pointing to "nowhere" memory address, no matter what the type is? 回答1: The question here is basically "why does the compiler not take into account the fact that it knows that the

return reference of an object from an iterator

你说的曾经没有我的故事 提交于 2020-01-03 06:49:29
问题 I want to return a reference of an object from a vector, and the object is in an iterator object. How can I do that? I tried the following: Customer& CustomerDB::getCustomerById (const string& id) { vector<Customer>::iterator i; for (i = customerList.begin(); i != customerList.end() && !(i->getId() == id); ++i); if (i != customerList.end()) return *i; // is this correct? else return 0; // getting error here, cant return 0 as reference they say } In the code, customerList is a vector of

Is there a way to combine Java8 Optional returning a value with printing a message on null?

不问归期 提交于 2020-01-03 06:42:09
问题 I'm starting with this code: String startingValue = getMyValue(); String finishingValue = ""; if (startingValue != null) { finishingValue = startingValue; } else { System.out.println("Value was null"); } I want to transform it using Java 8 options to something like this: Optional<String> startingOptional = getMyOptional(); String finishingValue = startingOptional .map(value -> value) .orElse(System.out.println("value not found")); My question is: Is there a way to combine Java8 Optional

Why can't I cast generic-type with null? [duplicate]

邮差的信 提交于 2020-01-03 06:39:42
问题 This question already has answers here : Why cannot convert null to type parameter T in c#? (3 answers) Closed last month . A similar question, but without casting the T parameter. This does not work public T GetValueG<T>(string Query) { object value = DBNull.Value; // Read from Database which can return DBNull if (value is DBNull) return (T)null; else return (T)value; } Error CS0037 Cannot convert null to 'T' because it is a non-nullable value type But this works public T GetValueG<T>(string

flask_restplus' marshal_with returns response with null values

最后都变了- 提交于 2020-01-03 05:17:07
问题 I am using flask_restplus to create a documented API. The marshal decorator controls what data actually gets rendered in your response, but I am having trouble rendering the data. I have the following code: kpis_model = api.model('kpis', { 'cpl_actual': fields.Integer(description='costo por lead total del mes actual'), 'cpl_anterior': fields.Integer(description='costo por lead total del mes anterior'), 'cpl_diferencia': fields.Integer(description='diferencia de cpl_actual y cpl_anterior') })